oracle 必须声明 PL/SQL 标识符“字符串”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9105801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PL/SQL identifier 'string' must be declared
提问by atrueresistance
Can anyone tell me why this won't execute?
谁能告诉我为什么这不会执行?
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;
Errors are below
错误如下
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
I guess I don't know why it isn't being declared since they are being declared in the type_emp.
我想我不知道为什么没有声明它,因为它们是在 type_emp 中声明的。
回答by Justin Cave
You'd need to use the record when you're referencing them. Your calls to dbms_output.put_line
also need to have an underscore between put
and line
.
当您引用它们时,您需要使用该记录。您对 的调用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.