–此處由linux伺服器下
1.授權建立目錄的許可權
grant
create
any directory to username;
2.建立目錄
create
orreplace directory op_file as
3.讀寫對應目錄許可權
grant
write,read
on directory oradir to username;
4.授權給使用者使用utl_file包的許可權
grant
execute
on utl_file to username;
5.檔案寫入
create
or replace procedure
proc_rw_file
isline
varchar2
(32767);
out_file utl_file.file_type; --定義乙個檔案型別
type c_type is ref cursor;
cur_sp_out c_type;
begin
--開啟指定目錄的檔案。op_file是檔案所在的目錄,xx.txt是要讀取的檔案,r檔案寫入的模式 w:寫,
--檔案不存在則建立,會覆蓋 a:追加 r:讀 注意:這裡的op_file需要用單引號引起來
--此處for迴圈包含個人業務
for emp in (select a.uuid, a.drsj, a.tbsj, a.tname, a.qhbm, b.xqjoint
from t_imp_rec a
inner join fx_tablename b
on (a.tname = b.tname)
where rownum = 1)
loop
begin
out_file := utl_file.fopen('op_file',
emp.uuid || '_' || emp.tname || '.txt',
'w');
open cur_sp_out for -- 利用游標操作動態sql結果
'select ' || emp.xqjoint || ' from ' || emp.tname || ' where tbsj = :tbsj and scsj = :scsj and qhbm like :qhbm'
using emp.tbsj, emp.drsj, emp.qhbm || '%';
loop
fetch cur_sp_out
into line;
exit when cur_sp_out%notfound;
utl_file.put_line(out_file,line);
--不建議使用put
endloop;
close cur_sp_out;
utl_file.fflush(out_file);
utl_file.fclose(out_file); --關閉檔案流
end;
endloop;
end;
oracle的檔案(UTL FILE)操作
oracle提供了乙個能否對作業系統操作的工具包utl file 想要oracle對檔案進行操作就要先建立乙個directory來指向作業系統目錄下的具體某個目錄 create directory report dir as home oracle chenlong report dir 為建立di...
Oracle日誌檔案常用操作
oracle關於日誌檔案基本操作 1.查詢系統使用的是哪一組日誌檔案 select from v log 2.查詢正在使用的組所對應的日誌檔案 select from v logfile 3.強制日誌切換 alter system switch logfile 4.查詢歷史日誌 select fro...
Oracle 控制檔案的操作
1,檢視資料檔案和重做日誌檔案 select member from v logfile 查詢日誌檔案 select name from v datafile 查詢資料檔案 select name from v controlfile 查詢控制檔案2,關閉資料庫 shutdown immediate...