博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
采用oracle存储过程读取excel文件更新表
阅读量:6957 次
发布时间:2019-06-27

本文共 1505 字,大约阅读时间需要 5 分钟。

如下所示:

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

转载地址:http://dpmil.baihongyu.com/

你可能感兴趣的文章
Linux操作命令(六)
查看>>
1、压滤机工作原理
查看>>
设计模式学习总结-桥接模式(Bridge Pattern)
查看>>
halcon算子翻译——copy_image
查看>>
使用Haar分类器进行面部检测
查看>>
参数化(四):处理非均匀数据分布
查看>>
Makefile-2
查看>>
获取页面中出现次数最多的三个标签以及出现次数
查看>>
访问WEB-INF目录中的文件
查看>>
web接口开发与测试
查看>>
php -- php控制linux关机、重启、注销
查看>>
867. Transpose Matrix
查看>>
十.python面向对象(itme)
查看>>
Python下selenium的简单用法
查看>>
multiset的应用
查看>>
我的mysql的学习记录
查看>>
Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
查看>>
NYOJ 题目77 开灯问题(简单模拟)
查看>>
模式识别
查看>>
设置文本编辑器的按回车时触发的事件
查看>>