--loop ...exit; when ...end loop; 大于2000的薪资
--select * from emp where emp.sal>2000 ;
declare
temp_salary emp.sal%type; --%type:通常是指某行某列数据类型 一个字段
temp_emp emp%rowtype; --%rowtype:通配一行所有列的数据类型 如v_row_test%rowtype;匹配emp表中的一行数据
cursor mycursor is ---游标(cursor)
select * from emp where emp.sal>temp_salary;
begin
temp_salary:=2000;
open mycursor;
loop
fetch mycursor into temp_emp;
exit when mycursor%notfound;--找不到数据时
dbms_output.put_line('ename:'||temp_emp.ename||'薪资'||temp_emp.sal);
end loop;
end;
----- for i in 1...n loop...end loop;
declare
temp_emp emp%rowtype;
cursor cur is select * from emp where emp.sal>2000;
begin
if cur%isopen=false then --判断游标是否打开
open cur;
end if;
for i in 0..6 loop
fetch cur into temp_emp;
exit when cur%notfound;
dbms_output.put_line('ename:'||temp_emp.ename||' ,sal:'||temp_emp.sal);
end loop;
close cur;
end;