条件判断语句

条件判断语句

  ifcase语句

  If语句

If语法

   Ifexpression1then pl/sql_statement

   Else

        Pl/sql_statement;

   End if;

Ifexpression1then pl/sql_statement

   Else ifexpression2

        Pl/sql_statement;

   Else

        Pl/sql_statement;

   End if;

 Case语句

     oracle9i以后引入

     Case <selector>

        When <expression1> then pl/sql_statement1;

        When <expression2> then pl/sql_statement2;

        …….

        [else  pl/sql_statement;]

     End;

//案例

SQL> declare score number(2) :=80;

   begin

       if score>70 then dbms_output.put_line('成绩合格');

   end if;

   end;

  /

SQL> declare score number(2) :=80;

   begin if score>90 then dbms_output.put_line('成绩合格');

 else dbms_output.put_line('成绩不合格');

end if;

end;

/

成绩不合格

SQL> declare score number(2):=8;

begin

case score

when 9 then dbms_output.put_line('成绩优秀');

when 8 then dbms_output.put_line('成绩亮');

end case;

end;

 /

循环语句

  最基本的循环称为无条件循环,如果没有指定exit语句,循环将无条件执行,这种循环称为死循环,死循环尽量避免。

语法格式如下:

     Loop

       ---statement---

 Exit when condition

 End loop;

 案例:

SQL> declare

      i number(2):=1;

       begin

            loop

              dbms_output.put_line(i);

                   i:=i+1;

          exit when i>10;

          end loop;

          end;

   /

While循环

    语法:

    While condition

         Loop

           Statement;

        End loop;

 SQL> declare

     i number(2):=1;

         begin

           while i<10  

              loop dbms_output.put_line(i);

                i:=i+1;

             end loop;

          end;

  /

For循环

     For loop_control_variable in [reverse] lower upper loop

          Statement;

        End loop;

  SQL> begin

         for i in 1..10

            loop

            dbms_output.put_line(i);

           end loop;

       end;

      / 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值