PL/SQL逻辑运算符
逻辑运算符
下表显示了PL/SQL支持的逻辑运算符。所有这些操作符布尔运算,并产生布尔结果。假设变量A=true,变量B=false,那么:
运算符 | 描述 | 示例 |
---|---|---|
and | 称为逻辑AND运算。如果两个操作数为true,则条件为true | (A and B) 结果为 false. |
or | 所谓的逻辑或操作。如果任何两个操作数为true,则条件变为true | (A or B) 结果为 true. |
not | 所谓逻辑非运算符。用于反向操作数的逻辑状态。如果条件为true,那么逻辑非运算符将使它为false | not (A and B) 结果为 true. |
运算符:
DECLARE a boolean := true; b boolean := false; BEGIN IF (a AND b) THEN dbms_output.put_line('Line 1 - Condition is true'); END IF; IF (a OR b) THEN dbms_output.put_line('Line 2 - Condition is true'); END IF; IF (NOT a) THEN dbms_output.put_line('Line 3 - a is not true'); ELSE dbms_output.put_line('Line 3 - a is true'); END IF; IF (NOT b) THEN dbms_output.put_line('Line 4 - b is not true'); ELSE dbms_output.put_line('Line 4 - b is true'); END IF; END; /
当上述代码在SQL提示符执行时,它产生了以下结果:
Line 2 - Condition is true Line 3 - a is true Line 4 - b is not true PL/SQL procedure successfully completed.