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.
参考链接
https://www.learnfk.com/plsql/plsql-if-then-elsif.html
标签:dbms,无涯,boolean,ELSIF,SQL,put,line,expression From: https://blog.51cto.com/u_14033984/8944969