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;