• 存储过程 100w提交


    1. create or replace procedure largedata_insert(ip_table_name   in varchar2, --目标表  
    2.                                           ip_table_column in varchar2, --目标字段  
    3.                                           ip_table_select in varchar2, --SELECT 查询语句  
    4.                                           return_result   out number --返回的结果1,表示成功,0表示失败  
    5.                                           ) as  
    6. --适合大数据量的插入模板  create Templates by chenzhoumin 20110614  
    7.   runTime number;  
    8.   i       number;  
    9.   amount  number;  
    10.   s_sql   varchar2(5000);  
    11. begin  
    12.   return_result := 0; --开始初始化为0  
    13.   --核必逻辑内容,可根据具体的业务逻辑来定义  
    14.   s_sql := 'select count(1) from (' || ip_table_select || ')';  
    15.   execute immediate s_sql  
    16.     into amount;  
    17.   --每100万提交一次  
    18.   runTime := amount mod 1000000;  
    19.   if (runTime > 0) then  
    20.     runTime := 1 + trunc(amount / 1000000);  
    21.   end if;  
    22.   if (runTime = 0) then  
    23.     runTime := 0 + trunc(amount / 1000000);  
    24.   end if;  
    25.   FOR i IN 1 .. runTime LOOP  
    26.     execute immediate 'insert into ' || ip_table_name || ' (' ||  
    27.                       ip_table_column || ')  
    28.      select ' || ip_table_column || ' from (select selectSec.*, rownum rownumType  
    29.           from (' || ip_table_select ||  
    30.                       ') selectSec  
    31.          WHERE ROWNUM <= ' || i * 1000000 || ')  
    32.  WHERE rownumType > ' || (i - 1) * 1000000;  
    33.     --提交  
    34.     commit;  
    35.   END LOOP;  
    36.   return_result := 1;  
    37.   dbms_output.put_line('结束' || to_char(sysdate, 'yyyymmddhh24miss'));  
    38.   return;  
    39. exception  
    40.   when others then  
    41.     return_result := 0;  
    42.     raise;  
    43.     return;  
    44. end;
  • 相关阅读:
    Fedora/CentOS/RHEL删除旧的内核
    Linux下使Shell命令脱离终端运行
    保持tmux窗口名更改后不变
    Centos7 修改ssh 默认端口号
    验证码生成代码
    Json帮助类代码
    Http请求代码
    cookies读写代码
    缓存读写代码
    数据读写 CommonCurd
  • 原文地址:https://www.cnblogs.com/huangyin/p/5684095.html
Copyright © 2020-2023  润新知