0

我有三个游标声明为 CUR_AD1、CUR_AD1_C、CUR_AD_2。它们所包含的只是来自 3 个运行良好的选择语句的结果。

后来我有以下陈述:

BEGIN

    FOR AD1_REC IN CUR_AD1 LOOP

      V_ORG_NAME := AD1_REC.ADDRESS_LINE1;


    IF V_ORG_NAME = AD1_REC.ADDRESS_LINE1 THEN
        INSERT INTO DSOPI_PERSON_ADDR_RULE 
        (CCTR_PERSON_ADDRESS_ID, CCTR_PERSON_ID, SRC_ADDRESS_LINE1, SRC_ADDRESS_LINE2, SRC_ADDRESS_LINE3, SRC_ADDRESS_LINE4, 
        ORG_NAME, DEPT_NAME, TGT_ADDRESS_LINE1, TGT_ADDRESS_LINE2, TGT_ADDRESS_LINE3, TGT_ADDRESS_LINE4, 
        STATE, CITY, COUNTRY_NAME, ZIP_CODE, EXTRACT_DATE) 
        VALUES
        (AD1_REC.CCTR_PERSON_ADDRESS_ID, AD1_REC.CCTR_PERSON_ID, AD1_REC.ADDRESS_LINE1, AD1_REC.ADDRESS_LINE2, AD1_REC.ADDRESS_LINE3, AD1_REC.ADDRESS_LINE4, 
         V_ORG_NAME, '', '', AD1_REC.ADDRESS_LINE2, AD1_REC.ADDRESS_LINE3, AD1_REC.ADDRESS_LINE4, 
         AD1_REC.STATE, AD1_REC.CITY, AD1_REC.COUNTRY_NAME, AD1_REC.ZIP_CODE, SYSDATE);

    ELSIF V_ORG_NAME = AD1_REC.ADDRESS_LINE2 THEN
      FOR AD2_REC IN CUR_AD2 LOOP

        INSERT INTO DSOPI_PERSON_ADDR_RULE 
        (CCTR_PERSON_ADDRESS_ID, CCTR_PERSON_ID, SRC_ADDRESS_LINE1, SRC_ADDRESS_LINE2, SRC_ADDRESS_LINE3, SRC_ADDRESS_LINE4, 
        ORG_NAME, DEPT_NAME, TGT_ADDRESS_LINE1, TGT_ADDRESS_LINE2, TGT_ADDRESS_LINE3, TGT_ADDRESS_LINE4,
        STATE, CITY, COUNTRY_NAME, ZIP_CODE, EXTRACT_DATE) 
        VALUES
        (AD2_REC.CCTR_PERSON_ADDRESS_ID, AD2_REC.CCTR_PERSON_ID, AD2_REC.ADDRESS_LINE1, AD2_REC.ADDRESS_LINE2, AD2_REC.ADDRESS_LINE3, AD2_REC.ADDRESS_LINE4, 
         AD2_REC.ADDRESS_LINE2, NULL, AD2_REC.TGT_ADDRESS_LINE1, NULL, AD2_REC.ADDRESS_LINE3, AD2_REC.ADDRESS_LINE4, 
         AD2_REC.STATE, AD2_REC.CITY, AD2_REC.COUNTRY_NAME, AD2_REC.ZIP_CODE, SYSDATE);
         END LOOP;
         END IF;

END LOOP;                
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR' || SQLERRM);
RAISE;    
END; 

当我编译正文时,我不断收到以下错误:

PL/SQL:忽略 SQL 语句 PLS-00302:必须声明组件“ZIP_CODE” PL/SQL:ORA-00984:此处不允许列

桌子没有任何问题。我认为这与我如何放置控制语句有关。非常感谢任何帮助。

表 DSOPI_PERSON_ADDR_RULE 的 DDL

  CREATE TABLE "CALSEED_OWNER"."DSOPI_PERSON_ADDR_RULE" 
   (    "CCTR_PERSON_ADDRESS_ID" NUMBER(12,0), 
    "CCTR_PERSON_ID" NUMBER(12,0), 
    "SRC_ADDRESS_LINE1" VARCHAR2(100 BYTE), 
    "SRC_ADDRESS_LINE2" VARCHAR2(100 BYTE), 
    "SRC_ADDRESS_LINE3" VARCHAR2(100 BYTE), 
    "SRC_ADDRESS_LINE4" VARCHAR2(100 BYTE), 
    "ORG_NAME" VARCHAR2(100 BYTE), 
    "DEPT_NAME" VARCHAR2(100 BYTE), 
    "TGT_ADDRESS_LINE1" VARCHAR2(100 BYTE), 
    "TGT_ADDRESS_LINE2" VARCHAR2(100 BYTE), 
    "TGT_ADDRESS_LINE3" VARCHAR2(100 BYTE), 
    "TGT_ADDRESS_LINE4" VARCHAR2(100 BYTE), 
    "STATE" VARCHAR2(100 BYTE), 
    "CITY" VARCHAR2(100 BYTE), 
    "COUNTRY_NAME" VARCHAR2(100 BYTE), 
    "ZIP_CODE" VARCHAR2(100 BYTE), 
    "EXTRACT_DATE" DATE, 
    "STREET" VARCHAR2(100 BYTE), 
    "STREET_CONTD" VARCHAR2(100 BYTE)

CURSOR CUR_AD2 IS         
        SELECT CCTR_PERSON_ADDRESS_ID, 'AL2' AL,ADDRESS_LINE2 
        FROM STG_RT2_PERSON_ADDRESS WHERE UPPER(ADDRESS_LINE2) IN 
        ( SELECT UPPER(ORG_NAME) FROM STG_RT2_ORGANIZATION
        WHERE NOT REGEXP_LIKE(ORG_NAME, '[0-9]') 
        AND NOT (LOWER(ORG_NAME) LIKE 'unknown' OR LOWER(ORG_NAME) LIKE 'no address%'
        OR ORG_NAME ='-' OR ORG_NAME=' ')); 
4

2 回答 2

2

出于调试目的,您可以使用

DBMS_UTILITY.format_error_backtrace;

确保游标中的所有别名(不仅是表)与您尝试访问的列匹配,例如

FOR x IN SELECT zip_code zipCode FROM myTable LOOP
    dbms_output.put_line(x.zip_Code)
END LOOP;

该示例中断是因为 x 包含 zipCode 而不是 zip_code。

使用您提供的信息,我们无法提供任何进一步的帮助,发布您的表的描述以及您的游标声明或制作可编译的示例。

这很有用http://sqlfiddle.com/

编辑

问题是你的游标声明

  SELECT
    CCTR_PERSON_ADDRESS_ID,
    'AL2' AL,
    ADDRESS_LINE2,
    ZIP_CODE -- ADD THIS FOR THE ZIP CODE, YOU NEED TO ADD ALL THE OTHER COLUMNS ASWELL...
 FROM
    STG_RT2_PERSON_ADDRESS
  WHERE
    UPPER(ADDRESS_LINE2) IN
    (
      SELECT
        UPPER(ORG_NAME)
      FROM
        STG_RT2_ORGANIZATION
      WHERE
        NOT REGEXP_LIKE(ORG_NAME, '[0-9]')
      AND NOT
        (
          LOWER(ORG_NAME) LIKE 'unknown'
        OR LOWER(ORG_NAME) LIKE 'no address%'
        OR ORG_NAME ='-'
        OR ORG_NAME =' '
        )
    ); 

每个 CUR_AD_2 都是您的结果集上的一条记录,因此它具有相同数量的列和名称,在您的查询中,您只有 3 列,但您试图访问其中很多(如邮政编码)不在光标; 确保添加 ZIP_CODE 和所需的所有其他列。或者只是从 INSERT 语句中删除它们

于 2012-10-18T05:08:23.993 回答
0

请检查表中的 zip_code 拼写 matchecs 列名

于 2012-10-18T04:12:46.393 回答