waterye

          使用utl_file包進行io操作

          1. 首先要創建目錄
          CREATE DIRECTORY log_dir AS 'd:/ora_log';

          2. 寫log
          DECLARE
            p_dir       
          varchar2(100);
            p_filename  
          varchar2(100);
            output_file utl_file.file_type;
          begin
            p_dir       :
          = 'log_dir';
            p_filename  :
          = 'log_' || to_char(sysdate, 'yyyy_mm_dd_HH24_MI_SS'|| '.txt';
            output_file :
          = utl_file.fopen(upper(p_dir), p_filename, 'w');
            
          delete from test;
            utl_file.put(output_file, 'test:  ' || SQL%ROWCOUNT || ' rows deleted.');

            utl_file.new_line(output_file);
            
          insert into test
              
          select * from test@remotedb;
            utl_file.put(output_file, 
          'test:  ' || SQL%ROWCOUNT || ' rows inserted.');
            utl_file.new_line(output_file);
            utl_file.fclose(output_file);
            
          commit;
          EXCEPTION
            
          WHEN OTHERS THEN
                utl_file.put(output_file, 'error: ' || to_char(sysdate, 'yyyy-mm-dd HH24:MI:SS'));
                utl_file.new_line(output_file);
                utl_file.put(output_file, 'SQLCODE:'||SQLCODE);
                utl_file.new_line(output_file);
                utl_file.put(output_file, 'SQLERRM:'||SQLERRM);
                utl_file.new_line(output_file);
                utl_file.fclose(output_file);   
              
          ROLLBACK;
          end;
          /

          參考:
          1. PL/SQL Packages and Types Reference
          2. AskTom
          3. Itpub

          posted on 2005-12-31 17:57 waterye 閱讀(861) 評論(0)  編輯  收藏 所屬分類: oracle

          主站蜘蛛池模板: 宜城市| 峨眉山市| 沛县| 巴楚县| 乌鲁木齐县| 肃北| 巴里| 济阳县| 图木舒克市| 铁岭市| 阿拉善盟| 伊吾县| 正镶白旗| 兴化市| 安阳县| 德钦县| 浪卡子县| 浮梁县| 兴安盟| 开化县| 广东省| 义马市| 平潭县| 屏东市| 九龙县| 靖安县| 江华| 平湖市| 景宁| 石城县| 岚皋县| 宣城市| 丰顺县| 务川| 宝清县| 古蔺县| 日喀则市| 新巴尔虎左旗| 德保县| 永寿县| 伊金霍洛旗|