Oracle几种游标的写法
第一种方式:
declare
lv_deptno emp.deptno%type:=10;
lv_ename emp.ENAME%type:='';
cursor find_emps_bydeptno(v_deptno number) is select ename from emp where deptno=v_deptno;
begin
open find_emps_bydeptno(lv_deptno);
loop
fetch find_emps_bydeptno into lv_ename;
exit when find_emps_bydeptno%notfound;
dbms_output.put_line('name:'||lv_ename);
end loop;
close find_emps_bydeptno;
end;
第二种方式:
declare
lv_deptno emp.deptno%type:=10;
cursor find_emps_bydeptno(v_deptno number) is select ename from emp where deptno=v_deptno;
begin
for v_obj in find_emps_bydeptno(lv_deptno)
loop
dbms_output.put_line('name:'||v_obj.ename);
end loop;
end;
第三种方式:
declare
lv_deptno emp.deptno%type:=10;
begin
for v_obj in (select ename from emp where deptno=lv_deptno)
loop
dbms_output.put_line('name:'||v_obj.ename);
end loop;
end;