首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

PL/SQL循环话语的使用

2012-09-04 
PL/SQL循环语句的使用循环语句?--1.基本循环DECLAREi INT:1BEGINLOOPEXIT WHEN i10dbms_output.put_li

PL/SQL循环语句的使用

循环语句

?

--1.基本循环DECLARE        i INT:=1;BEGIN        LOOP                 EXIT WHEN i=10;            dbms_output.put_line(i);            i :=i+1;        END LOOP;END;

?输出结果:

1
2
3
4
5
6
7
8
9

--2.WHILE循环DECLARE        i int :=1;BEGIN        WHILE i<=10 LOOP              dbms_output.put_line(i);              i := i+1;        END LOOP;END;

?

输出结果:

1
2
3
4
5
6
7
8
9
10

?

--3.FOR循环--REVERSE 是可选的BEGIN        FOR i IN REVERSE 1..10 LOOP            dbms_output.put_line(i);                    END LOOP;END;

?

输出结果:

10
9
8
7
6
5
4
3
2
1

?

--4.嵌套循环和标号declare        result int;begin       <<outer>>       for i in 1..100 loop           <<inter>>           for j in 1..100 loop               result := i * j;               exit outer when result = 1000;               exit when result = 500;           end loop inner;                              dbms_output.put_line(result);       end loop outer;                      dbms_output.put_line(result);end;

?

输出结果:

100
200
300
400
500
600
700
800
900
500
1100
1200
1300
1400
1500
1600
1700
1800
1900
500
2100
2200
2300
2400
500
2600
2700
2800
2900
3000
3100
3200
3300
3400
3500
3600
3700
3800
3900
1000

?

?

?

热点排行