小布老师-PL_SQL(第九讲)

一、false、true、null 的逻辑运算 如上图所示;

二、循环语句LOOP

       Syntax:

       LOOP

               statement1;

                ......................

                exit [ where  condition ];

        end LOOP;

三、while 循环

       WHILE CONDITION LOOP

                     STATEMENT1;

                      STATEMENT2;

       END LOOP;

四、for循环

     for  counter   in  [ reverse ]

            lower_bound..upper_bound  LOOP

             STATEMENTS1;

             STATEMENTS2;

             ....

      end loop;

      1)  User a FOR loop to  shortcut the test for the number of iterations

       2)  Do not  declare the counter ; it is declared implicity.

        3)  DECLARE

                    V_countryid  locations.country_id %type := 'CA';

                     v_loc_id         locations.location_id %TYPE ;

                    v_new_city     locations.city%type := 'Montreal';

             BEGIN

                         SELECT MAX(  location_id ) into  v_loc_id  FROM  locations

                          where   country_id  =  v_countryid;

                          FOR  i   IN  1...3  LOOP  ---i  只能递增1,如果不想则请使用其他的循环如while 设置 

                                          INSERT INTO  locations (location_id ,city, country_id)

                                          VALUES (   (v_loc_id +i)  , v_new_city , v_countryid);

                          END LOOP;

           END;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值