我想从table1(etudiant)中获得一个值,以便使用slect在table2(employee)中使用该值,我使用cursor,但是我没有得到结果;你能帮我谢谢吗
declare
cle employee.id%type;
cursor cur_test is select id from etudiant where name ='Hichem';
no_data_found exception;
begin
open cur_test;
loop
fetch cur_test into cle;
exit when cur_test%notfound;
end loop;
--dbms_output.put_line('ID IS ' ||cle);
select * from employee where id=cle;
if cur_test%rowcount=0 then
close cur_test;
raise no_data_found;
end if;
close cur_test;
exception
when no_data_found then
dbms_output.put_line('no data found');
end;
/
看起来您过于复杂了。您为什么不直接加入etudiant
并参加会议employee
?像这样:
begin
for cur_r in (select e.name
from employee e join etudiant t on t.id = e.id
where t.name = 'Hichem'
)
loop
dbms_output.put_line(cur_r.name);
end loop;
end;
/
也许您甚至不需要循环。或者,如果您要查找的姓名不止一个人(Hichem
在这种情况下),则可以这样做。
从您的代码:
no_data_found
; 这是预定义的异常select * from employees
错误的-在PL / SQL中-您必须选择结果INTO
。如果您希望一行以上,请考虑将集合与bulk collect
我用游标刚度来学习;谢谢 ;