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

2021-08-30 16:37 更新

在PL/SQL編程中嵌套IF-ELSE語句總是合法的,也就是說可以在一個(gè)IF或ELSE IF語句中使用另一個(gè)IF或ELSE IF語句。

語法

PL/SQL中嵌套IF-ELSE語句的語法是 -

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;
SQL

實(shí)例

請參考以下示例代碼 -

SET SERVEROUTPUT ON SIZE 1000000;
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

當(dāng)上述代碼在SQL提示符下執(zhí)行時(shí),它會產(chǎn)生以下結(jié)果 -






以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號