PolarDB for Oracle supports three logical operators: AND, OR, and NOT. SQL uses three-valued Boolean logic, where null represents unknown. This means that expressions involving null do not always evaluate to TRUE or FALSE.
Operator signatures
Each operator accepts Boolean inputs and returns a Boolean result:
boolean AND boolean → boolean
boolean OR boolean → boolean
NOT boolean → booleanTruth tables
AND/OR
| a | b | a AND b | a OR b |
|---|---|---|---|
TRUE | TRUE | TRUE | TRUE |
TRUE | FALSE | FALSE | TRUE |
TRUE | NULL | NULL | TRUE |
FALSE | FALSE | FALSE | FALSE |
FALSE | NULL | FALSE | NULL |
NULL | NULL | NULL | NULL |
NOT
| a | NOT a |
|---|---|
TRUE | FALSE |
FALSE | TRUE |
NULL | NULL |
Examples
-- AND: returns rows where both conditions are true
SELECT * FROM employees WHERE job_id = 'PU_CLERK' AND department_id = 30;
-- OR: returns rows where either condition is true
SELECT * FROM employees WHERE job_id = 'PU_CLERK' OR department_id = 10;
-- NOT: returns rows where the condition is false
SELECT * FROM employees WHERE NOT (job_id IS NULL);Commutativity
AND and OR are commutative — switching the left and right operands does not affect the result.