带参数的光标
cursor 光标名 [(参数名 数据类型[,参数名 数据类型]...)]
is select 语句;
案例
--查询某个部门中员工的姓名
SET SERVEROUTPUT ON
DECLARE
--定义带参数的光标
cursor cemp(dno number)is select first_name,last_name from EMPLOYEES where EMPLOYEES.DEPARTMENT_ID = dno;
pe_first_name EMPLOYEES.FIRST_NAME%TYPE;
pe_last_name EMPLOYEES.LAST_NAME%TYPE;
BEGIN
--打开光标
open cemp(60);
loop
--取出每个员工的姓名
FETCH cemp into pe_first_name,pe_last_name;
exit when cemp%notfound;
DBMS_OUTPUT.PUT_LINE(pe_first_name||' '||pe_last_name);
end loop;
--关闭光标
close cemp;
end;
/