PL/SQL 中的 IF

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

IF-THEN-ELSIF 语句允许您在几种选择之间进行选择, IF-THEN  语句后可以是可选的 ELSIF ... ELSE 语句, ELSIF 子句允许您添加其他条件。

IF-THEN-ELSIF - 语法

PL/SQL编程语言中的 IF-THEN-ELSIF 语句的语法为-

IF(boolean_expression 1)THEN  
   S1; -- Executes when the boolean expression 1 is true  
ELSIF( boolean_expression 2) THEN 
   S2;  -- Executes when the boolean expression 2 is true  
ELSIF( boolean_expression 3) THEN 
   S3; -- Executes when the boolean expression 3 is true  
ELSE  
   S4; -- executes when the none of the above condition is true  
END IF; 

IF-THEN-ELSIF - 示例

DECLARE 
   a number(3) := 100; 
BEGIN 
   IF ( a = 10 ) THEN 
      dbms_output.put_line('Value of a is 10' ); 
   ELSIF ( a = 20 ) THEN 
      dbms_output.put_line('Value of a is 20' ); 
   ELSIF ( a = 30 ) THEN 
      dbms_output.put_line('Value of a is 30' ); 
   ELSE 
       dbms_output.put_line('None of the values is matching'); 
   END IF; 
   dbms_output.put_line('Exact value of a is: '|| a );  
END; 
/

当以上代码在SQL提示符下执行时,将产生以下输出-

无涯教程网

None of the values is matching 
Exact value of a is: 100  

PL/SQL procedure successfully completed. 

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

技术教程推荐

深入浅出gRPC -〔李林锋〕

微服务架构实战160讲 -〔杨波〕

零基础学Python -〔尹会生〕

TensorFlow快速入门与实战 -〔彭靖田〕

Swift核心技术与实战 -〔张杰〕

重学线性代数 -〔朱维刚〕

容器实战高手课 -〔李程远〕

徐昊 · TDD项目实战70讲 -〔徐昊〕

徐昊 · AI 时代的软件工程 -〔徐昊〕

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