我正在执行以下代码片段
set serveroutput on;
DECLARE
TYPE emp_rec_type IS record (emp_id NUMBER,salary NUMBER);
emp_rec emp_rec_type;
l_out number;
l_statement varchar2(1000);
BEGIN
emp_rec.emp_id := 1;
emp_rec.salary := 1000;
SELECT emp_rec.salary INTO l_out FROM dual WHERE 1=1;
dbms_output.put_line(l_out);
l_statement := 'select emp_rec.salary from dual where 1=1';
execute immediate l_statement into l_out;
dbms_output.put_line(l_out);
END;
我得到以下输出
Error report:
ORA-00904: "EMP_REC"."SALARY": invalid identifier
ORA-06512: at line 23
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
1000
我期望输出是
1000
1000
为什么动态语句执行坚持 emp_rec.salary 是一个无效的标识符,而 Select into 语句工作正常?我还需要做些什么才能使其正常工作吗?