转载自网易博客http://blog.163.com/xuejelly1985@126/blog/static/362103402008823101415479/
1、for--loop循环
declare
s_no student.sno%type;
cursor c1 is
select sno from student where sno>'10001';
begin
for i in c1 loop
dbms_output.put_line(i.sno);
end loop;
end;
/
--游标的FOR循环,在FOR循环中,是隐含的自带游标的打开和关闭。
2、loop--end loop循环
declare
s_no student.sno%type;
cursor c1 is
select sno from student where sno>'10001';
begin
open c1;
loop
fetch c1 into s_no;
exit when c1%notfound;
dbms_output.put_line(s_no);
end loop;
close c1;
exception
when no_data_found then
dbms_output.put_line('no data1');
end;
/
--一般的LOOP循环,要显示的打开和关闭游标,而且要特别的注意循环条件的退出与输出的前后关系。
3、if判断
declare
cursor c1 is
select sno from student where sno>'10001';
begin
for i in c1 loop
if(i.sno<10004) then
dbms_output.put_line(i.sno);
end if;
end loop;
end;
/
--一种简单的条件判断。