使用游标打印员工姓名和薪水
set serveroutput on;
declare
cursor cemp is select ename,sal from emp;
cname emp.ename%type;
csal emp.sal%type;
begin
open cemp;
loop
fetch cemp into cname,csal;
exit when cemp%notfound;
dbms_output.put_line(cname || '的薪水是' || csal);
end loop;
end;
/
带参数的游标使用游标打印某部门号的所有员工姓名
set serveroutput on;
declare
cursor cemp(cno emp.deptno%type) is select ename from emp where emp.deptno = cno;
cname emp.ename%type;
begin
open cemp(10);
loop
fetch cemp into cname;
exit when cemp%notfound;
dbms_output.put_line(cname);
end loop;
end;
/