CURSOR cursor_name(parameter_name datatype) IS select_statement; --只能制定类型,不能指定具体大小
OPEN cursor_name(参数值);
FECTH cursor_name INTO variable,...;
CLOSE cursor_name;
declare cursor emp_cursor(v_depnto number) is select ename,sal from scott.emp where deptno = v_depnto order by empno;
emp_record emp_cursor%rowtype; v_dno number;
begin v_dno := &no;
if not emp_cursor%isopen then open emp_cursor(v_dno);
end if; null;
loop fetch emp_cursor into emp_record;
exit when emp_cursor%notfound; dbms_output.put_line('姓名:'||emp_record.ename||',工资:'||emp_record.sal);
end loop; null;
if emp_cursor%isopen then close emp_cursor;
end if; end;
?
|