必须声明 PL/SQL 标识符“字符串”
Posted
技术标签:
【中文标题】必须声明 PL/SQL 标识符“字符串”【英文标题】:PL/SQL identifier 'string' must be declared 【发布时间】:2012-02-02 01:11:43 【问题描述】:谁能告诉我为什么这不会执行?
set serveroutput on ;
Declare
TYPE type_emp IS RECORD(
emp_name employees.last_name%TYPE,
emp_salary employees.salary%TYPE);
rec_emp type_emp;
due_for_a_raise CHAR(1);
begin
SELECT last_name, salary into rec_emp
from employees
where employee_id = 150;
if emp_salary > 5000 then
due_for_a_raise := 'Y';
else
due_for_a_raise := 'N';
end if;
dbms_output.putline(last_name);
dbms_output.putline(salary);
dbms_output.putline(due_for_a_raise);
end;
错误如下
Error report:
ORA-06550: line 11, column 6:
PLS-00201: identifier 'EMP_SALARY' must be declared
ORA-06550: line 11, column 3:
PL/SQL: Statement ignored
ORA-06550: line 16, column 23:
PLS-00201: identifier 'LAST_NAME' must be declared
ORA-06550: line 16, column 3:
PL/SQL: Statement ignored
ORA-06550: line 17, column 23:
PLS-00201: identifier 'SALARY' must be declared
ORA-06550: line 17, column 3:
PL/SQL: Statement ignored
ORA-06550: line 18, column 15:
PLS-00302: component 'PUTLINE' must be declared
ORA-06550: line 18, column 3:
PL/SQL: Statement ignored
我想我不知道为什么它没有被声明,因为它们是在 type_emp 中声明的。
【问题讨论】:
【参考方案1】:您在引用它们时需要使用记录。您对dbms_output.put_line
的调用也需要在put
和line
之间有一个下划线。
SQL> ed
Wrote file afiedt.buf
1 Declare
2 TYPE type_emp IS RECORD(
3 emp_name employees.last_name%TYPE,
4 emp_salary employees.salary%TYPE);
5 rec_emp type_emp;
6 due_for_a_raise CHAR(1);
7 begin
8 SELECT last_name, salary
9 into rec_emp
10 from employees
11 where employee_id = 150;
12 if rec_emp.emp_salary > 5000 then
13 due_for_a_raise := 'Y';
14 else
15 due_for_a_raise := 'N';
16 end if;
17 dbms_output.put_line(rec_emp.emp_name);
18 dbms_output.put_line(rec_emp.emp_salary);
19 dbms_output.put_line(due_for_a_raise);
20* end;
SQL> /
PL/SQL procedure successfully completed.
【讨论】:
以上是关于必须声明 PL/SQL 标识符“字符串”的主要内容,如果未能解决你的问题,请参考以下文章
PL SQL,错误(32,43):PLS-00201:必须声明标识符“HR”
在 PL/SQL 中出现错误“PLS-00201:必须声明标识符‘JSON_VALUE’”
PL/SQL 函数中的 XmlRoot、XmlElement、InsertChildXml 给出 PLS-00201 必须声明标识符
ORA-06550:第 1 行,第 7 列:PLS-00201:必须声明标识符“PAYMENT_UPDATE” ORA-06550:第 1 行,第 7 列:PL/SQL:语句被忽略