2017-12-03 22 views
0

私はcourse_no、departおよびenrollmentという3つの異なる入力を受け入れようとしています。 しかし、私はこのエラーを取得しています:無効な識別子PL/SQL

old 4: select count(*) into DeptFound from dept where dept = &depart; 
new 4: select count(*) into DeptFound from dept where dept = csce; 
select count(*) into DeptFound from dept where code = csce; 
                * 

ERROR at line 4: 
ORA-06550: line 4, column 56: 
PL/SQL: ORA-00904: "CSCE": invalid identifier 
ORA-06550: line 4, column 2: 
PL/SQL: SQL Statement ignored 

マイDEPTクラスは、char型(4)のコード列を持っているので、それが無効の識別子である理由私は知りません。このよう

select count(*) into DeptFound from dept where dept = csce; 
-- => 
select count(*) into DeptFound from dept where dept = 'csce'; 
               -- case-sensitive   
+0

そこに '&'を入れているのはなぜですか? '&depart'では? – bytepusher

+0

@bytepusher私はそれを削除し、それは私に同じエラーを与えている。しかし、今回は:PL/SQL:ORA-00904: "DEPART":無効な識別子 – Dani

答えて

0

用途:

ACCEPT course_no number PROMPT "Enter course_no "; 
ACCEPT Depart PROMPT "Enter Dept "; 
ACCEPT Enrollment number PROMPT "Enter Enrollment "; 

DECLARE 

BEGIN 
    select count(*) into Department from dept where code = &depart; 

END; 
/
1

あなたは文字列リテラルを使用する必要があります。

select count(*) into DeptFound from dept where dept = '&depart'; -- enter csce whenever prompts 

使用引用を、codeはchar型であるため、ここで は、私が持っているものです。常にリテラルの代わりにバインド変数を使うことを好む(より安全なアンチ・インジェクション&あなたのSQLは何度も何度も解析される必要はない)