gpt4 book ai didi

oracle - PLS-00302 : component must be declared- Unable to resolve

转载 作者:行者123 更新时间:2023-12-03 08:29:57 33 4
gpt4 key购买 nike

我在SQL Developer中尝试了以下程序,但遇到了一些问题:

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时出错,尽管已在记录中正确声明了它。

最佳答案

尝试:

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循环更加简单明了。

分享并享受。

关于oracle - PLS-00302 : component must be declared- Unable to resolve,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22306355/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com