zoukankan      html  css  js  c++  java
  • 采用oracle存储过程读取excel文件更新表

    如下所示:

    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输出文本的那个间隔字符才行。

  • 相关阅读:
    Python学习之路 (五)爬虫(四)正则表示式爬去名言网
    Python学习之路 (四)爬虫(三)HTTP和HTTPS
    Python学习之路 (三)爬虫(二)
    Python学习之路 (二)爬虫(一)
    Python学习之路 (一)开发环境搭建
    ZooKeeper学习之路 (十一)ZooKeeper API的应用
    ZooKeeper学习之路 (十)Hadoop的HA集群的机架感知
    Spring Security
    Spring Validation
    [转]linux下完全备份数据库mysql
  • 原文地址:https://www.cnblogs.com/lanzi/p/2625596.html
Copyright © 2011-2022 走看看