PL/SQL 中的 nested IF

首页 / PL/SQL入门教程 / PL/SQL 中的 nested IF

在PL/SQL编程中,将 IF-ELSE 语句嵌套通常是合法的,这意味着您可以在其中使用一个 IF 或 ELSE IF 语句另一个 IF 或 ELSE IF 语句。

嵌套 IF-THEN-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; 

嵌套 IF-THEN-ELSE - 示例

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. 

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

React实战进阶45讲 -〔王沛〕

算法面试通关40讲 -〔覃超〕

研发效率破局之道 -〔葛俊〕

分布式技术原理与算法解析 -〔聂鹏程〕

编译原理实战课 -〔宫文学〕

手把手教你玩音乐 -〔邓柯〕

大厂广告产品心法 -〔郭谊〕

JavaScript进阶实战课 -〔石川〕

结构思考力 · 透过结构看思考 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)