这必须是非常容易修复的东西,但由于某种原因,我无法让它工作。我一直收到错误
PLS-00201: identifier 'ART' must be declared
我的代码如下:
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;
我认为问题可能是当用户输入“艺术”时,程序将其作为“ART”并且因为我的表格类型是“Art”而不是“ART”,那么这就是我得到错误的原因。我似乎无法知道如何解决它的工作。有帮助吗?
对不起,我昨晚睡着了,这是我正在接受的完整错误
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.
答案 0 :(得分:1)
PLS-00201:标识符' ART'必须声明
我认为问题可能是当用户输入" Art"该计划将其作为" ART"因为我的桌子类型是" Art"不是" ART"那就是我收到错误的原因。
它与UPPER / LOWER案例无关。该查询被解析为:
SELECT TITLE into output FROM CLASS where TYPE=ART;
如果type是varchar类型,则必须将值作为字符串传递,即必须将其括在单引号中。否则,Oracle会将其解释为标识符。所以,它应该是:
SELECT TITLE into output FROM CLASS where TYPE='ART';
例如,
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>
而且,使用保留关键字作为对象名称并不是一个好主意。 TYPE是保留关键字。