oracle 寫檔案

generators發表於2009-11-18

----建立路徑
create or replace directory pass_path as 'd:houxt';

----建立寫的儲存過程
create or replace procedure proc_write(num number)
is
---create or replace directory pass_path as 'd:houxt';

cursor cur_dat is
select pass_no||'|'||pass_word||'|'||cre_date||'|'||pass_state as jilu from t
where rownum<=num;

fhandle utl_file.file_type;
err varchar2(100);
begin

-----注意這裡的路徑名大寫
fhandle := utl_file.fopen('PASS_PATH', 'pass.txt', 'w');

for dat in cur_dat loop
utl_file.put_line(fhandle ,dat.jilu);
end loop;

utl_file.fclose(fhandle);

exception when others then
err:=substr(sqlerrm,1,100);
end;

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9307930/viewspace-1028824/,如需轉載,請註明出處,否則將追究法律責任。

相關文章