declare
temp_salary employee.salary%type;
temp_emp employee%rowtype;
cursor mycursor is
select * from employee where employee.salary>temp_salary;
begin
temp_salary:=2000;
open mycursor;
loop
fetch mycursor into temp_emp;
exit when mycursor%notfound;
dbms_output.put_line('编号:'||temp_emp.empid||','||'名字:'||temp_emp.empname||','||'薪水:'||temp_emp.salary);
end loop;
end;
output:
loop
statament1;
exit when condition;
statament2;
end loop;
第二:for i in 1...n loop...end loop;
declare
temp_emp employee%rowtype;
cursor cur2 is select * from employee where employee.salary>2000;
begin
if cur2%isopen = false then
open cur2;
end if;
for i in 0..3 loop
fetch cur2 into temp_emp;
exit when cur2%notfound;
dbms_output.put_line('编号:'||temp_emp.empid||','||'名字:'||temp_emp.empname||','||'薪水:'||temp_emp.salary);
end loop;
close cur2;
end;
output: