採用oracle預存程序讀取excel檔案更新表

來源:互聯網
上載者:User

如下所示:

CREATE OR REPLACE PROCEDURE p_xlstooracle IS
   v_file                utl_file.file_type;
   out_v                 VARCHAR2(4000);
   v_id                  NUMBER;
   v_service_competition NUMBER;
   v_cu_market_share     NUMBER(6, 4);
   v_ct_market_share     NUMBER(6, 4);
   v_cm_market_share     NUMBER(6, 4);
   v_other_market_share  NUMBER(6, 4);
BEGIN
   IF utl_file.is_open(v_file) THEN
      utl_file.fclose(v_file);
   END IF;
   v_file := utl_file.fopen('UTL_FILE_DIR', 'i_exch_info2.xls', 'r');
   LOOP
      BEGIN
         utl_file.get_line(v_file, out_v);
      EXCEPTION
         WHEN no_data_found THEN
            EXIT;
      END;
      v_id   := substr(out_v, 1, instr(out_v, '    ', 1, 1) - 1);
      v_service_competition := substr(out_v,
                       instr(out_v, '    ', 1, 1) + 1,
                       instr(out_v, '    ', 1, 2) - instr(out_v, '    ', 1, 1)-1);
      v_cu_market_share := substr(out_v,
                       instr(out_v, '    ', 1, 2) + 1,
                       instr(out_v, '    ', 1, 3) - instr(out_v, '    ', 1, 2)-1);
      v_ct_market_share := substr(out_v,
                       instr(out_v, '    ', 1, 3) + 1,
                       instr(out_v, '    ', 1, 4) - instr(out_v, '    ', 1, 3)-1);
      v_cm_market_share := substr(out_v,
                       instr(out_v, '    ', 1, 4) + 1,
                       instr(out_v, '    ', 1, 5) - instr(out_v, '    ', 1, 4)-1);
      v_other_market_share := substr(out_v,
                       instr(out_v, '    ', 1, 5) + 1,
                       length(out_v) - instr(out_v, '    ', 1, 5));
      UPDATE i_exch_info
         SET service_competition = v_service_competition,
             cu_market_share     = v_cu_market_share,
             ct_market_share     = v_ct_market_share,
             cm_market_share     = v_cm_market_share,
             other_market_share  = v_other_market_share
       WHERE gwm_fid = v_id;
      dbms_output.put_line(out_v);
   END LOOP;
   utl_file.fclose(v_file);
END p_xlstooracle;

註:分隔字元不是空格,我是直接拷貝的excel輸出文本的那個佔空間字元才行。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.