日期:2014-05-16  浏览次数:20454 次

oracle存储过程执行中输出日志文件
create or replace procedure p_outputdebug(a varchar2,b varchar2,c varchar2)
is
  vFileName             varchar2(100);
  OutputFile            UTL_FILE.FILE_TYPE;
begin
     select 'rfid_'||a.rfid||'.log'
       into vFileName
       from tbl_animal_info a where a.rfid='330100000078176'

     ;
     OutputFile := utl_file.fopen('background_dump_dest',vFileName,'a');
     utl_file.putf(OutputFile,a,b,c);
     utl_file.fflush(OutputFile);
     utl_file.fclose(OutputFile);
end ;


SQL> create or replace directory "background_dump_dest"as 'D:\database\cares100\bdump';

Directory created

SQL> grant read on directory "background_dump_dest" to myuser;

Grant succeeded

SQL> grant write on directory "background_dump_dest" to myuser;

Grant succeeded

SQL> call myuser.p_outputdebug('1','1','1');

Method called

--需要注意的一点是:日志目录需创建在oracle所在服务器上,否则报错。

UTL_FILE.FOPEN 用法
参考http://blog.csdn.net/cnham/article/details/5927700
我的异常网推荐解决方案:oracle存储过程,http://www.aiyiweb.com/oracle-develop/177537.html