PL / SQL:ORA-00942:表或视图不存在

时间:2012-11-05 17:01:43

标签: plsql

我收到此错误' PL / SQL:ORA-00942:当我试图破坏我的部分脚本时,Oracle 11G中的表或视图不存在' 。看来select语句似乎没有从游标中解析变量的名称。需要帮助以确保这可以从光标读取表名变量。

DECLARE
  ITEM_ERROR     NUMBER;
  CNT_SITE       VARCHAR2(46);

  CURSOR C_SITEID IS
     SELECT OBJECTNAME,ATTRIBUTENAME FROM MAXATTRIBUTE    WHERE ATTRIBUTENAME LIKE 'SITE%'   GROUP BY OBJECTNAME,ATTRIBUTENAME, COLUMNNAME;            
     SITEIDRec    C_SITEID%RowType;

 BEGIN
 BEGIN
 OPEN C_SITEID;
 LOOP
   FETCH C_SITEID into SITEIDRec;
   EXIT WHEN C_SITEID %NOTFOUND;
       BEGIN  
         SELECT COUNT(SITEID) into CNT_SITE FROM SITEIDRec.OBJECTNAME
          WHERE  SITEID  IN ('COLLEGE NANO SCI ENG-TGCM','FREESCALE-BALAZS','TGCM-GLOBAL FOUNDRIES','INTL RECTIFIER-TGM','TGCM-DMOS5','TGCM-IMFT','TGCM-TRIQUINT','GP-TRIQUINT');
       EXCEPTION
          WHEN NO_DATA_FOUND THEN NULL;
       END;
 END LOOP;
 --COMMIT;
 CLOSE C_SITEID;
 --COMMIT;
 EXCEPTION
    WHEN NO_DATA_FOUND THEN NULL;
 END;
 --COMMIT;
  EXCEPTION
    WHEN OTHERS THEN
    MSG_TEXT := SUBSTR(SQLERRM,1,200);
  --COMMIT;
   raise;
END;

1 个答案:

答案 0 :(得分:4)

我认为您的查询中有FROM TableName 缺失,因此它正在抱怨。

SELECT COUNT(SITEID) into SITEIDRec.OBJECTNAME
      WHERE SITEID IN 
             ('COLLEGE NANO SCI ENG-TGCM','FREESCALE-BALAZS',
               'TGCM-GLOBAL FOUNDRIES','INTL RECTIFIER-TGM','TGCM-DMOS5',
               'TGCM-IMFT','TGCM-TRIQUINT','GP-TRIQUINT');

请添加From TableName

以更正您的查询

编辑:尝试使用EXECUTE IMMEDIATE,如下所示

 EXECUTE IMMEDIATE 'SELECT COUNT(SITEID) into CNT_SITE FROM ' 
                    || SITEIDRec.OBJECTNAME ||
         ' WHERE SITEID IN (''COLLEGE NANO SCI ENG-TGCM'',''FREESCALE-BALAZS'',
               ''TGCM-GLOBAL FOUNDRIES'',''INTL RECTIFIER-TGM'',''TGCM-DMOS5'',
               ''TGCM-IMFT'',''TGCM-TRIQUINT'',''GP-TRIQUINT'')';