鍍金池/ 教程/ 數(shù)據(jù)庫/ PL/SQL嵌套IF-THEN-ELSE語句
PL/SQL記錄
PL/SQL基本語法
PL/SQL集合
PL/SQL包
PL/SQL關系運算符
PL/SQL比較運算符
PL/SQL條件控制
PL/SQL字符串
PL/SQL算術運算符
PL/SQL變量
PL/SQL IF-THEN-ELSIF語句
PL/SQL函數(shù)
PL/SQL異常
PL/SQL FOR循環(huán)語句
PL/SQL日期及時間
PL/SQL EXIT語句
PL/SQL DBMS輸出
PL/SQL過程
PL/SQL CONTINUE語句
PL/SQL數(shù)組
PL/SQL嵌套IF-THEN-ELSE語句
PL/SQL事務
PL/SQL CASE語句
PL/SQL IF-THEN語句
PL/SQL GOTO語句
PL/SQL運算符優(yōu)先級
PL/SQL觸發(fā)器
PL/SQL運算符
PL/SQL教程
PL/SQL WHILE循環(huán)語句
PL/SQL面向對象
PL/SQL循環(huán)
PL/SQL邏輯運算符
PL/SQL IF-THEN-ELSE語句
PL/SQL數(shù)據(jù)類型
PL/SQL環(huán)境安裝設置
PL/SQL游標
PL/SQL基本循環(huán)語句
PL/SQL搜索CASE語句
PL/SQL常量和文字
PL/SQL嵌套循環(huán)

PL/SQL嵌套IF-THEN-ELSE語句

PL/SQL編程嵌套if-else語句,可以使用一個IF或ELSE IF語句中的另一個IF或ELSE IF語句。

語法:

IF( boolean_expression 1)THEN
    -- executes when the boolean expression 1 is true 
    IF(boolean_expression 2) THEN
      -- executes when the boolean expression 2 is true 
      sequence-of-statements;
   END IF;
ELSE
   -- executes when the boolean expression 1 is not true
  else-statements;
END IF;

示例:

DECLARE
   a number(3) := 100;
   b number(3) := 200;
BEGIN
   -- check the boolean condition 
   IF( a = 100 ) THEN
   -- if condition is true then check the following 
      IF( b = 200 ) THEN
      -- if condition is true then print the following 
         dbms_output.put_line('Value of a is 100 and b is 200' );
      END IF;
   END IF;
   dbms_output.put_line('Exact value of a is : ' || a );
   dbms_output.put_line('Exact value of b is : ' || b );
END;
/

當上述代碼在SQL提示符執(zhí)行時,它產(chǎn)生了以下結果:

Value of a is 100 and b is 200
Exact value of a is : 100
Exact value of b is : 200

PL/SQL procedure successfully completed.