1、修改init.ora文件,设置utl_file_dir参数
如utl_file_dir='/ora01/test'
2、建立如下过程
create or replace procedure sp_test_write_file
(text_content in varchar2)
is
file_handle utl_file.file_type;
begin
--open file
file_handle:=utl_file.fopen(location=>'/ora01/test',filename=>'My_File.txt',open_mode=>'W');
--write file
utl_file.put_line(file_handle,text_content);
--close file
utl_file.fclose(file_handle);
exception
when others then
raise;
end sp_test_write_file;
需要先打开一个句柄,然后操作,最后关闭该句柄。