在 IF-THEN 语句序列之后可以是 ELSE 语句的可选序列,它们在条件为 FALSE 时执行。
语法 for the IF-THEN-ELSE statement is -
IF condition THEN S1; ELSE S2; END IF;
其中, S1 和 S2 是不同的语句序列。在 IF-THEN-ELSE语句中,当测试条件为TRUE时,执行语句 S1 并跳过 S2 ;当测试条件为FALSE时,将绕过 S1 并执行语句 S2 。例如-
IF color=red THEN dbms_output.put_line('You have chosen a red car') ELSE dbms_output.put_line('Please choose a color for your car'); END IF;
如果布尔表达式条件的值为true,则将执行 if-then代码块,否则将执行else代码块。
链接:https://www.learnfk.comhttps://www.learnfk.com/plsql/plsql-if-then-else.html
来源:LearnFk无涯教程网
让无涯教程尝试一个示例,以帮助您理解概念-
DECLARE a number(3) := 100; BEGIN -- check the boolean condition using if statement IF( a < 20 ) THEN -- if condition is true then print the following dbms_output.put_line('a is less than 20 ' ); ELSE dbms_output.put_line('a is not less than 20 ' ); END IF; dbms_output.put_line('value of a is : ' || a); END; /
当以上代码在SQL提示符下执行时,将产生以下输出-
a is not less than 20 value of a is : 100 PL/SQL procedure successfully completed.
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)