本帖最后由 lgq_0714 于 2011-04-26 00:55:21 编辑

解决方案 »

  1.   

    declare  i integer; 
    begin
    select count(*) into i from user_tables where table_name='MDMC_T_NOTIFY_TEMP';
    if i>0 then
       execute immediate 'drop table MDMC_T_NOTIFY_TEMP';
    end if;select count(*) into i from user_tables where table_name='SIS_T_NOTIFYDATA_TEMP';
    if i>0 then
       execute immediate 'drop table SIS_T_NOTIFYDATA_TEMP';
    end if;execute immediate 'create table MDMC_T_NOTIFY_TEMP as select * from MDMC_T_NOTIFY where 1=0';
    execute immediate 'create table SIS_T_NOTIFYDATA_TEMP as select * from SIS_T_NOTIFYDATA where 1=0';end;
    这个用TRUNCATE就行了,避免过多的DDL操作,MDMC_T_NOTIFY_TEMP 临时表插入速度很快的还有,插入的时候用APPEND,
      

  2.   

    IF MOD(COUNTS,ONETIME_COMMIT)=0 THEN
              COMMIT;
      END IF;
           COUNTS := COUNTS + 1;
    ---上面这个有存在的必要吗?你的意思是不是每过1000条提交一次,oracle不希望有频繁的提交。只要一个commit就行。
    ---根据你上面需求,我感觉没有必要用游标实现,在plsql里,循环插入会增加plsql和sql语句的上下文切换的开销。直接用表关联执行sql语句就行。
    ---增加 execute immediate 'alter table MDMC_T_NOTIFY_TEMP nologging';
    -- execute immediate 'alter table SIS_T_NOTIFYDATA_TEMP nologging';
    --包括1楼说的。
      

  3.   

    应该是2个delete操作比较慢吧,插入4万多条数据很快的。
    MDMC_NOTIFY,SIS_T_NOTIFYDATA这2个表都比较大吧。
    可以使用rowid尝试下。
    eg:
    begin
      for i in (select a.rowid rd, from MDMC_NOTIFY a,MDMC_T_NOTIFY_TEMP b where a,b表关联)
      loop
        delete from MDMC_NOTIFY where rowid=i.rd;
      end loop;
      commit;
    end;
    /
      

  4.   

    1. 直接用表关联执行sql语句就行
    2. 如果用游标循环,建议使用绑定变量:execute immediate 'INSERT INTO MDMC_T_NOTIFY_TEMP 
    SELECT * FROM MDMC_T_NOTIFY where NOTIFYID=:V_NOTIFYID and DESTTYPE=''IB'' AND FACTORYNAME=''SISTaskFactory''' using V_NOTIFYID;
      

  5.   

    CREATE OR REPLACE PROCEDURE PROC_MDMC_T_NOTIFY(v_id) ;OPEN MDMC_NOTIFY FOR SELECT NOTIFYID FROM MDMC_T_NOTIFY WHERE DESTTYPE='IB' AND FACTORYNAME='SISTaskFactory' and mod(NOTIFYID ,5) = v_id;execute PROC_MDMC_T_NOTIFY(0) ; 
    execute PROC_MDMC_T_NOTIFY(1) ; 
    execute PROC_MDMC_T_NOTIFY(2) ; 
    execute PROC_MDMC_T_NOTIFY(3) ; 
    execute PROC_MDMC_T_NOTIFY(4) ;