PL/SQL的loop循环
2015-05-27 14:31
567 查看
转载自网易博客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;
/
--一种简单的条件判断。
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;
/
--一种简单的条件判断。
相关文章推荐
- Oracle:PL/SQL--流程控制(三)——循环结构:loop、while-loop、for-loop
- Oracle PL/SQL之LOOP循环控制语句
- oracle PL/SQL的基本构成,结构控制语句,分支结构,选择结构,loop循环结构,
- Oracle PL/SQL之LOOP循环控制语句
- Oracle PL/SQL之LOOP循环控制语句
- Oracle PL/SQL之LOOP循环控制语句
- Oracle PL/SQL之LOOP循环控制语句
- PL/SQL中使用EXISTS:使用LOOP循环替代或者SELECT实现类似的功能:
- Oracle PL/SQL之LOOP循环控制语句
- pl/sql中的控制语句应用: 循环语句 loop和for
- 【DB.PL/SQL】程序流程控制 —— 循环 ——LOOP, END LOOP, WHILE, FOR, CONTINUE
- PL/SQL语句学习之使用while、loop和for三种循环打印数字的1-10
- Oracle PL/SQL之LOOP循环控制语句
- Oracle PL/SQL之LOOP循环控制语句
- Oracle PL/SQL之LOOP循环控制语句
- Oracle PL/SQL之LOOP循环控制语句
- Oracle PL/SQL之LOOP循环控制语句
- PL/SQL中LOOP循环控制语句
- PL/SQL编码规范: 注释、变量命名、书写格式、逻辑分支、 循环处理
- PL/SQL的定义(五)循环控制