Plsql-logical-operators

提供:Dev Guides
移動先:案内検索

PL/SQLの論理演算子

次の表に、PL/SQLでサポートされる論理演算子を示します。 これらのすべての演算子はブール値オペランドで機能し、ブール値の結果を生成します。 変数Aがtrueを保持し、変数Bがfalseを保持すると仮定します-

Operator Description Examples
and Called the logical AND operator. If both the operands are true then condition becomes true. (A and B) is false.
or Called the logical OR Operator. If any of the two operands is true then condition becomes true. (A or B) is true.
not Called the logical NOT Operator. Used to reverse the logical state of its operand. If a condition is true then Logical NOT operator will make it false. not (A and B) is 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.