0

我有正在选择数据的光标,它运行得很好

CURSOR Crs_c1 IS
SELECT a.GLOBAL_ACCOUNT_CODE,
       a.LOCAL_ACCOUNT_CODE,
       a.LOCAL_ACCOUNT_NAME,
       c.GLOBAL_ACCOUNT_TYPE  t_conto,
       ltrim(rtrim(a.GLOBAL_ACCOUNT_CODE))||ltrim(rtrim(a.LOCAL_ACCOUNT_CODE)) GLOBAL_LOCAL
 FROM  V_LOCAL_ACCOUNTS@GDW_LIVE  a,V_GLOBAL_ACCOUNTS@GDW_LIVE  c --V_LOCAL_ACCOUNTS@GDWPP_ANY  a,V_GLOBAL_ACCOUNTS@GDWPP_ANY  c
 WHERE a.enabled_flag = 'Y'
 AND a.GLOBAL_ACCOUNT_CODE=c.GLOBAL_ACCOUNT_CODE
 AND not exists (SELECT 1
                 FROM conto_gdw b   -- considero solo i conti nuovi
                 WHERE a.LOCAL_ACCOUNT_CODE = b.c_conto_local_gdw
                AND   a.GLOBAL_ACCOUNT_CODE=b.C_CONTO_GLOBAL_GDW);

但是在插入时代码失败....

INSERT INTO conto_gdw
                    (C_CONTO_LOCAL_GDW,
                     S_CONTO_LOCAL_GDW,
                     C_CONTO_GLOBAL_GDW,
                     T_CONTO,
                     D_INIZIO,
                     GLOBAL_LOCAL)
             VALUES (Rec_Crs_c1.LOCAL_ACCOUNT_CODE,
                     nvl(Rec_Crs_c1.LOCAL_ACCOUNT_NAME,'.'),
                     Rec_Crs_c1.GLOBAL_ACCOUNT_CODE,
                     Rec_Crs_c1.t_conto,
                     (v_anno_in * 100) + v_mese_in,
                     Rec_Crs_c1.GLOBAL_LOCAL);

可能是由于单个元组(数据集)而发生此问题。我怎样才能找到罪魁祸首数据?我已经通过将光标选择的所有数据放入excel表中检查了它,但我无法手动找到任何东西。ORACLE 有没有办法将失败的数据返回给我?

4

1 回答 1

0

您需要在插入数据时进行适当的异常处理。提供 pl sql 块的输出。之后我们可以帮助您。

DECLARE
   CURSOR Crs_c1
   IS
      SELECT   a.GLOBAL_ACCOUNT_CODE,
               a.LOCAL_ACCOUNT_CODE,
               a.LOCAL_ACCOUNT_NAME,
               c.GLOBAL_ACCOUNT_TYPE t_conto,
               LTRIM (RTRIM (a.GLOBAL_ACCOUNT_CODE))
               || LTRIM (RTRIM (a.LOCAL_ACCOUNT_CODE))
                  GLOBAL_LOCAL
        FROM   V_LOCAL_ACCOUNTS@GDW_LIVE a, V_GLOBAL_ACCOUNTS@GDW_LIVE c 
       WHERE   a.enabled_flag = 'Y'
               AND a.GLOBAL_ACCOUNT_CODE = c.GLOBAL_ACCOUNT_CODE
               AND NOT EXISTS
                     (SELECT   1
                        FROM   conto_gdw b     -- considero solo i conti nuovi
                       WHERE   a.LOCAL_ACCOUNT_CODE = b.c_conto_local_gdw
                               AND a.GLOBAL_ACCOUNT_CODE =
                                     b.C_CONTO_GLOBAL_GDW);

Rec_Crs_c1 Crs_c1%ROWTYPE;
BEGIN
   OPEN Crs_c1;

   LOOP
      FETCH Crs_c1 INTO   Rec_Crs_c1;

      EXIT WHEN Crs_c1%NOTFOUND;

      INSERT INTO conto_gdw (C_CONTO_LOCAL_GDW,
                             S_CONTO_LOCAL_GDW,
                             C_CONTO_GLOBAL_GDW,
                             T_CONTO,
                             D_INIZIO,
                             GLOBAL_LOCAL)
        VALUES   (Rec_Crs_c1.LOCAL_ACCOUNT_CODE,
                  NVL (Rec_Crs_c1.LOCAL_ACCOUNT_NAME, '.'),
                  Rec_Crs_c1.GLOBAL_ACCOUNT_CODE,
                  Rec_Crs_c1.t_conto,
                  (v_anno_in * 100) + v_mese_in,
                  Rec_Crs_c1.GLOBAL_LOCAL);
   END LOOP;

   CLOSE Crs_c1;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Error Message' || SQLERRM);
      DBMS_OUTPUT.put_line(   'GLOBAL_ACCOUNT_CODE :'
                           || Rec_Crs_c1.LOCAL_ACCOUNT_CODE
                           || 'LOCAL_ACCOUNT_CODE '
                           || Rec_Crs_c1.LOCAL_ACCOUNT_NAME
                           || 'GLOBAL_ACCOUNT_CODE :'
                           || Rec_Crs_c1.GLOBAL_ACCOUNT_CODE
                           || 'GLOBAL_ACCOUNT_TYPE '
                           || Rec_Crs_c1.t_conto
                           || 'GLOBAL_LOCAL'
                           || Rec_Crs_c1.GLOBAL_LOCAL);
END;
于 2012-12-04T14:00:20.843 回答