1、简化写法
declare
cursor cur_emp is select empno,ename,sal from emp order by empno;
begin
for cv_emp in cur_emp
loop
dbms_output.put_line('empno='||cv_emp.empno||',ename='||cv_emp.ename||',sal='||cv_emp.sal);
end loop;
end;
2、传统写法
declare
v_empno emp.empno%type;
v_ename emp.ename%type;
v_sal emp.sal%type;
cursor cur_emp is select empno,ename,sal from emp order by empno;
begin
open cur_emp;
loop
fetch cur_emp into v_empno,v_ename,v_sal;
exit when cur_emp%notfound;
dbms_output.put_line('empno='||v_empno||',ename='||v_ename||',v_sal='||v_sal);
end loop;
close cur_emp;
end;
declare
cursor cur_emp is select empno,ename,sal from emp order by empno;
begin
for cv_emp in cur_emp
loop
dbms_output.put_line('empno='||cv_emp.empno||',ename='||cv_emp.ename||',sal='||cv_emp.sal);
end loop;
end;
2、传统写法
declare
v_empno emp.empno%type;
v_ename emp.ename%type;
v_sal emp.sal%type;
cursor cur_emp is select empno,ename,sal from emp order by empno;
begin
open cur_emp;
loop
fetch cur_emp into v_empno,v_ename,v_sal;
exit when cur_emp%notfound;
dbms_output.put_line('empno='||v_empno||',ename='||v_ename||',v_sal='||v_sal);
end loop;
close cur_emp;
end;