使用提交间隔从一个 table 插入另一个

Insert from one table into another with commit Intervals

我编写了一个程序,用于将数据从一个 table 插入另一个 table。数据量巨大 - 总共 1.06 亿行。所以我想在查询上设置一个提交间隔。

我发现这个脚本通常可以正常工作并且不需要时间来完成工作,但我不知道为什么我在

上出错
INSERT INTO dlc_pr_activity_remise   
VALUES (add all values using ga_array(i).<value in select>)

错误:

Error(51,1): PL/SQL: SQL Statement ignored
Error(51,47): PL/SQL: ORA-00917: missing comma

我的程序:

create or replace
PROCEDURE ACTIVITY1 AS 
BEGIN
DECLARE 
commit_interval pls_integer := 250000 ; 
uncommitted pls_integer := 0; 
fetch_size  pls_integer := 2500 ; 
cursor g1 is SELECT prr.EVT_DECLENCHEUR ,
                    prr.BQ_CDF ,
                    prr.BQ_DOM ,
                    prr.NUM_COMMERCANT ,
                    prr.TYPE_CONTRAT_COM ,
                    prr.COMMERCANT_SIRET ,
                    prr.TYPE_PRE_COMP ,
                    prr.BQ_CDF_ID_EBF ,
                    prr.BQ_DOM_ID_EBF ,
                    prr.DAT_TRAITEMENT ,
                    prr.EVT_TYPE_OPERATION ,
                    prr.DEV_MT_CRE ,
                    prr.NBR_DECI_MT_CRE ,
                    prr.REF_FICHIER_TRAITE ,
                    prr.NUM_CTC ,
                    prr.REF_FICHIER_ORIGINE ,
                    prr.ORIGINE_FLUX ,
                    prr.NUM_EST_REMISE ,
                    prr.NUM_REMISE_ORIGINE ,
                    prr.NUM_MACHINE ,
                    prr.REF_ARCHIVAGE_REM ,
                    prr.DAT_REMISE ,
                    prr.SUPPORT_REMISE ,
                    prr.DAT_REMISE_CALCULEE ,
                    prr.DAT_VALEUR_REMISE ,
                    prr.COD_APPLI ,
                    to_date(SYSDATE,'DD/MM/YYYY')
                    FROM dlc_pr_remise prr
                    WHERE NOT EXISTS
                      (SELECT *
                      FROM DLC_PR_ACTIVITY_REMISE prao
                      WHERE prao.num_est_remise = prr.num_est_remise
                      );
TYPE GL_T is table of gl%rowtype ; 
gl_array GL_T; 
begin 
open gl ; 
loop 
fetch gl 
bulk collect 
into gl_array 
limit fetch_size ; 
forall i in 1 .. gl_arary.count 
INSERT INTO dlc_pr_activity_remise values(add all values using ga_array(i).<value in select>)
uncommitted :+ uncommitted + sql%rowcount ; 
exit when gl_arary.count < fetch_size ; 
if uncommitted >= commit_interval 
then 
commit ; 
uncommitted := 0; 
end if ; 
end loop ; 
commit ; 
close gl; 
END ;
END ACTIVITY1;
cursor g1 is select acct_nbr from dwc_tmp_acct_rcvbl;

上面光标的select必须替换为:

SELECT prr.EVT_DECLENCHEUR ,
prr.BQ_CDF ,
prr.BQ_DOM ,
prr.NUM_COMMERCANT ,
prr.TYPE_CONTRAT_COM ,
prr.COMMERCANT_SIRET ,
prr.TYPE_PRE_COMP ,
prr.BQ_CDF_ID_EBF ,
prr.BQ_DOM_ID_EBF ,
prr.DAT_TRAITEMENT ,
prr.EVT_TYPE_OPERATION ,
prr.DEV_MT_CRE ,
prr.NBR_DECI_MT_CRE ,
prr.REF_FICHIER_TRAITE ,
prr.NUM_CTC ,
prr.REF_FICHIER_ORIGINE ,
prr.ORIGINE_FLUX ,
prr.NUM_EST_REMISE ,
prr.NUM_REMISE_ORIGINE ,
prr.NUM_MACHINE ,
prr.REF_ARCHIVAGE_REM ,
prr.DAT_REMISE ,
prr.SUPPORT_REMISE ,
prr.DAT_REMISE_CALCULEE ,
prr.DAT_VALEUR_REMISE ,
prr.COD_APPLI ,
to_date(SYSDATE,'DD/MM/YYYY')
  FROM dlc_pr_remise prr
  WHERE NOT EXISTS
    (SELECT *
    FROM DLC_PR_ACTIVITY_REMISE prao
    WHERE prao.num_est_remise = prr.num_est_remise
    )

然后,这一行:

insert into dwc_tmp_acct_rcvbl_year_col (acct_nbr) 

必须替换为

INSERT INTO dlc_pr_activity_remise values(add all values using ga_array(i).<value in select>)

希望对您有所帮助。

你可以用这个。您的代码中几乎没有错误,这就是编译时出现错误的原因。请将您的代码与下面的代码进行比较,找出您出错的地方。我的评论是内联的。

CREATE OR REPLACE PROCEDURE ACTIVITY1
AS  

   fetch_size  pls_integer := 100 ;

   CURSOR gl
   IS
      SELECT prr.EVT_DECLENCHEUR,
             prr.BQ_CDF,
             prr.BQ_DOM,
             prr.NUM_COMMERCANT,
             prr.TYPE_CONTRAT_COM,
             prr.COMMERCANT_SIRET,
             prr.TYPE_PRE_COMP,
             prr.BQ_CDF_ID_EBF,
             prr.BQ_DOM_ID_EBF,
             prr.DAT_TRAITEMENT,
             prr.EVT_TYPE_OPERATION,
             prr.DEV_MT_CRE,
             prr.NBR_DECI_MT_CRE,
             prr.REF_FICHIER_TRAITE,
             prr.NUM_CTC,
             prr.REF_FICHIER_ORIGINE,
             prr.ORIGINE_FLUX,
             prr.NUM_EST_REMISE,
             prr.NUM_REMISE_ORIGINE,
             prr.NUM_MACHINE,
             prr.REF_ARCHIVAGE_REM,
             prr.DAT_REMISE,
             prr.SUPPORT_REMISE,
             prr.DAT_REMISE_CALCULEE,
             prr.DAT_VALEUR_REMISE,
             prr.COD_APPLI,
             TO_DATE (SYSDATE, 'DD/MM/YYYY')
        FROM dlc_pr_remise prr
       WHERE NOT EXISTS
                (SELECT *
                   FROM DLC_PR_ACTIVITY_REMISE prao
                  WHERE prao.num_est_remise = prr.num_est_remise);

   TYPE GL_T IS TABLE OF gl%ROWTYPE;

   gl_array         GL_T;
BEGIN
   OPEN gl;

   LOOP
      FETCH gl BULK COLLECT INTO gl_array LIMIT fetch_size;

      FORALL i IN 1 .. gl_arary.COUNT
         INSERT INTO dlc_pr_activity_remise -- I assume the dlc_pr_activity_remise table has same columns which you are selectig in cursor.
              VALUES gl_arary (i);

      --Exit the loop when you cursor is empty.
      EXIT WHEN gl%NOTFOUND;

   END LOOP;

   COMMIT;

  CLOSE gl;

END ACTIVITY1;

uncommitted的增量需要为 未提交 := 未提交 + sql%rowcount ;

不像post 未提交 :+ 未提交 + sql%rowcount ;