--光标的使用
/*
光标的三个属性 1 notfound% isopen% rowcount%
*/
declare
--定义光标
cursor emp_cursor is select ename,sal from emp;
p_name emp.ename%type;
p_sal emp.sal%type;
begin
open emp_cursor;
loop
fetch emp_cursor into p_name,p_sal;
dbms_output.put_line(p_name||'的薪水是'||p_sal);
exit when emp_cursor%notfound;
end loop;
close emp_cursor;
end;
--带参数的光标
declare
cursor p_cursor(p_empno number) is select ename from emp where empno=p_empno;
p_ename emp.ename%type;
begin
open p_cursor(7369);
loop
fetch p_cursor into p_ename;
exit when p_cursor%notfound;
dbms_output.put_line(p_ename);
end loop;
close p_cursor;
end;
/*
光标的三个属性 1 notfound% isopen% rowcount%
*/
declare
--定义光标
cursor emp_cursor is select ename,sal from emp;
p_name emp.ename%type;
p_sal emp.sal%type;
begin
open emp_cursor;
loop
fetch emp_cursor into p_name,p_sal;
dbms_output.put_line(p_name||'的薪水是'||p_sal);
exit when emp_cursor%notfound;
end loop;
close emp_cursor;
end;
--带参数的光标
declare
cursor p_cursor(p_empno number) is select ename from emp where empno=p_empno;
p_ename emp.ename%type;
begin
open p_cursor(7369);
loop
fetch p_cursor into p_ename;
exit when p_cursor%notfound;
dbms_output.put_line(p_ename);
end loop;
close p_cursor;
end;