日期:2014-05-17 浏览次数:21085 次
--注册文件路径 directory DIR_AUDIT_FAIL_INFO is 'E:\audit_fail_info'; create or replace procedure P_CHECK_OUT_TO_FIELD(message out varchar2) is /*使用utl_file库包来定义文件句柄*/ v_file_handle utl_file.file_type; --文件句柄 v_filepath varchar2(500); --文件名 v_buffer varchar(1500); --缓冲区 local_code_1 varchar2(10); local_code_2 varchar2(10); local_code_3 varchar2(10); CURSOR c1 IS select local_code_1,local_code_2,local_code_3 from mid_serv_rel; begin FOR r1 in c1 LOOP /*使用DBMS_APPLICATION_INFO库包来获取文件名*/ DBMS_APPLICATION_INFO.read_client_info(v_filepath); if v_filepath is null then v_filepath := 'CHECK_OUT_FIELD' || TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') || '.csv'; DBMS_APPLICATION_INFO.set_client_info(v_filepath); end if; --打开一个文件句柄 v_file_handle := utl_file.fopen('DIR_AUDIT_FAIL_INFO', v_filepath, 'A'); --拼装信息,用“,”分割这样导出到csv文件中就分布在多列中 v_buffer := local_code_1 || ',' || local_code_2 || ',' || local_code_3 ; --写文件 utl_file.put_line(v_file_handle, v_buffer, true); utl_file.fclose(v_file_handle); message :='完成'; END LOOP; end P_CHECK_OUT_TO_FIELD;