PLS-00302:必须声明组件 - 无法解析 [英] PLS-00302: component must be declared- Unable to resolve
本文介绍了PLS-00302:必须声明组件 - 无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 SQL Developer 中尝试了以下程序,但遇到了一些问题:
I tried the below program in SQL developer and facing some issues:
declare
cursor emp_complex_cur is
select e.fname,d.dlocation
from employee e, dept_location d
where e.dno=d.dnumber;
emp_max_id integer;
type emp_complex_rec is record(rname employee.fname%type,rlocation dept_location.dlocation%type);
begin
open emp_complex_cur;
for emp_complex_rec in emp_complex_cur loop
fetch emp_complex_cur into emp_complex_rec;
dbms_output.put_line('The employee id is: '||emp_complex_rec.rname||' and the employee''s location is '||emp_complex_rec.rlocation);
close emp_complex_cur;
end;
我在声明变量 rname
时遇到错误,尽管它已在记录中正确声明.
I am getting the error to declare the variable rname
though it has been properly declared in the record.
推荐答案
尝试:
begin
for emp_complex_rec in (select e.fname,
d.dlocation
from employee e
INNER JOIN dept_location d
ON (e.dno = d.dnumber))
loop
dbms_output.put_line('The employee id is: ' ||
emp_complex_rec.rname ||
' and the employee''s location is ' ||
emp_complex_rec.rlocation);
end loop;
end;
原始代码的问题是 emp_complex_rec
作为类型的定义与作为游标循环变量的 emp_complex_rec
的定义发生冲突.也不需要显式游标定义 - IMO 将 SELECT
放在 FOR
循环中更容易、更清晰.
The problem with the original code was that the definition of emp_complex_rec
as a type was colliding with the definition of emp_complex_rec
as a cursor loop variable. The explicit cursor definition isn't needed either - IMO putting the SELECT
in the FOR
loop is easier and clearer.
分享和享受.
这篇关于PLS-00302:必须声明组件 - 无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文