简体   繁体   English

PLS-00201标识符必须声明

[英]PLS-00201 Identifier must be declared

This has got to be something really easy to fix, but for some reason I can't get it to work. 这必须确实很容易解决,但是由于某种原因我无法使其正常工作。 I keep getting the error 我不断收到错误

PLS-00201: identifier 'ART' must be declared

My code is the following: 我的代码如下:

create or replace PROCEDURE question1(givenType IN VARCHAR, output OUT CHAR,output1 OUT CHAR)
AS
BEGIN
SELECT TITLE into output FROM CLASS where TYPE=givenType;
SELECT INSTRUCTOR into output1 FROM CLASS where TYPE=givenType;
DBMS_OUTPUT.PUT_LINE('The title of any classes with that type is: '|| output|| 'The instructor that taught each class is: ' || output1);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data found');
END;

I think the problem may be that when the user inputs "Art" the program takes it in as "ART" and since my table type is "Art" not "ART" then that's why I get the error. 我认为问题可能在于,当用户输入“ Art”时,程序会将其作为“ ART”输入,并且由于我的表类型是“ Art”而不是“ ART”,所以这就是我收到错误的原因。 I just can't seem to know how to fix it to work. 我似乎不知道如何解决它。 Any help guys? 有帮助吗?

Sorry guys I fell asleep last night here is the full error that I'm getting 抱歉,昨晚我睡着了,这是我遇到的全部错误

Connecting to the database CS425 Spring 2015.
ORA-06550: line 6, column 16:
PLS-00201: identifier 'ART' must be declared
ORA-06550: line 6, column 3:
PL/SQL: Statement ignored
Process exited.
Disconnecting from the database CS425 Spring 2015.

PLS-00201: identifier 'ART' must be declared PLS-00201:必须声明标识符“ ART”

I think the problem may be that when the user inputs "Art" the program takes it in as "ART" and since my table type is "Art" not "ART" then that's why I get the error. 我认为问题可能在于,当用户输入“ Art”时,程序会将其作为“ ART”输入,并且由于我的表类型是“ Art”而不是“ ART”,所以这就是我收到错误的原因。

It has nothing to do with the UPPER/LOWER case. 它与UPPER / LOWER情况无关。 The query is parsed as: 该查询被解析为:

SELECT TITLE into output FROM CLASS where TYPE=ART;

If type is varchar type, then you must pass the value as a string, ie you must enclose it within single-quotation marks . 如果type是varchar type,则必须将值作为字符串传递,即必须将其用单引号引起来 Else, Oracle interprets it to be an identifier . 否则,Oracle将其解释为标识符 So, it should be: 因此,应为:

SELECT TITLE into output FROM CLASS where TYPE='ART';

For example, 例如,

SQL> SET SERVEROUTPUT ON
SQL> DECLARE
  2    o_dept NUMBER;
  3  BEGIN
  4    SELECT DEPTNO INTO o_dept FROM EMP WHERE ENAME=SCOTT;
  5    dbms_output.put_line(o_dept);
  6  END;
  7  /
  SELECT DEPTNO INTO o_dept FROM EMP WHERE ENAME=SCOTT;
                                                 *
ERROR at line 4:
ORA-06550: line 4, column 50:
PL/SQL: ORA-00904: "SCOTT": invalid identifier
ORA-06550: line 4, column 3:
PL/SQL: SQL Statement ignored


SQL> DECLARE
  2    o_dept NUMBER;
  3  BEGIN
  4    SELECT DEPTNO INTO o_dept FROM EMP WHERE ENAME='SCOTT';
  5    dbms_output.put_line(o_dept);
  6  END;
  7  /
20

PL/SQL procedure successfully completed.

SQL>

And, it is not a good idea to use reserved keywords as object names. 而且,使用保留关键字作为对象名称不是一个好主意。 TYPE is a reserved keyword. TYPE是保留关键字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM