- PL/SQL 教程
- PL/SQL - 主頁
- PL/SQL - 概述
- PL/SQL - 環境
- PL/SQL - 基本語法
- PL/SQL - 資料型別
- PL/SQL - 變數
- PL/SQL - 常量和字面量
- PL/SQL - 運算子
- PL/SQL - 條件
- PL/SQL - 迴圈
- PL/SQL - 字串
- PL/SQL - 陣列
- PL/SQL - 過程
- PL/SQL - 函式
- PL/SQL - 遊標
- PL/SQL - 記錄
- PL/SQL - 異常
- PL/SQL - 觸發器
- PL/SQL - 包
- PL/SQL - 集合
- PL/SQL - 事務
- PL/SQL - 日期和時間
- PL/SQL - DBMS 輸出
- PL/SQL - 面向物件
- PL/SQL 有用資源
- PL/SQL - 問與答
- PL/SQL - 快速指南
- PL/SQL - 有用資源
- PL/SQL - 論壇
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 提示符處執行上述程式碼時,將生成以下結果 -
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.
plsql_conditional_control.htm
廣告