ORALCE的几种IF条件判断语句

来源:互联网 发布:linux 脚本加入自启动 编辑:程序博客网 时间:2024/06/13 01:09


1. 撒子是IF...THEN...条件语句
格式:
IF THEN
END IF;

declare
x number :=9;
    begin
    if x<10 then
    dbms_output.put_line('x is less than10');
    end if;
   end;
   /
x is less than10

PL/SQL 过程已成功完成。


declare
x number :=9;
    begin
    if x<10 then
    insert into testloop values(1111);
    end if;
   end;
   /
SQL> select * from testloop;

         A
----------
      1111

 

2.撒子是IF...THEN...ELSE...条件语句
格式:
IF THEN
ELSE
END IF;

declare
x number :=20;
    begin
    if x<10 then
    insert into testloop values(1111);
    else
    insert into testloop values(2222);
    end if;
   end;
   /
SQL> select * from testloop;

         A
----------
      1111
  11143431
      2222


3.撒子是IF...THEN...,ELSEIF THEN...,ELSEIF...THEN,ELSE...END IF;
格式:
IF    THEN
 
ELSIF THEN
 
ELSIF THEN
 
ELSE
 
END IF;

 

DECLARE
x NUMBER(3) := 47;
BEGIN
  IF x < 10 THEN
    dbms_output.put_line('X is less than 10');
  ELSIF x = 10 THEN
    dbms_output.put_line('X is equal to 10');
  ELSIF x < 100 THEN
    dbms_output.put_line('X is between 11 and 99');
  ELSE
    dbms_output.put_line('X is greater than 99');
  END IF;
END;
/

 

原创粉丝点击