A. 如何把oracle 存储过程 输出到文本
分几个步骤
1,创建输出路径,比如你要在c盘test目录下输出,你就先要建立好这个test路径
2,sqlplus下以sysdba登录,执行以下语句
3,create or replace directory TMP as 'c: est'
4,grant read,write on directory TMP to 你要生成文件的用户;
5,alter system set utl_file_dir='c: est' scope=spfile;
以上步骤执行完,需要重启数据库
6,最重要的一步开始了,创建存储过程
createorreplacePROCEDURESP_OUTPUT
is
file_handleutl_file.file_type;
Write_contentVARCHAR2(1024);
Write_file_nameVARCHAR2(50);
v_idint;
v_formvarchar2(10);
cursorcur_sp_out
is
selectid,formfroma;
begin
opencur_sp_out;
loop
fetchcur_sp_outintov_id,v_form;
exitwhencur_sp_out%notfound;
write_file_name:=to_char(SYSDATE,'MMDD')||'.txt'
file_handle:=utl_file.fopen('TMP',write_file_name,'a');
write_content:=v_id||''||v_form;
--writefile
IFutl_file.is_open(file_handle)THEN
utl_file.put_line(file_handle,write_content);
ENDIF;
--closefile
utl_file.fclose(file_handle);
endloop;
closecur_sp_out;
end;
createtablea(idint,
formvarchar2(10));
insertintoavalues(1,'你好');
insertintoavalues(2,'你很好');
begin
SP_OUTPUT;
end;