In this tutorial, we'll learn how to use OR the Oracle operator to combine two or more Boolean expressions.
The Oracle or operator describes
ORThe operator is a logical operator that combines a Boolean expression and returns if one of the expressions is True ( true ) true .
ORThe syntax for the following description operator:
expression_1 AND expression_2
The following table shows the OR true results of the operators false between, and NULL values.
| value |
TRUE |
FALSE |
NULL |
| TRUE |
TRUE |
TRUE |
TRUE |
| FALSE |
TRUE |
FALSE |
Null |
| Null |
TRUE |
Null |
Null |
We often use operators in the WHERE clause of the SELECT,DELETE and UPDATE statements OR to form conditions for filtering data.
If more than one logical operator is used in a statement, Oracle NOT evaluates the operator after the evaluation and the AND operator OR . However, you can change the order of evaluation using parentheses.
Examples of Oracle or operators
We will use the tables in the sample database orders to demonstrate. The table structure looks like this-
1. Examples of two Boolean expressions combined with Oracle or operator
The following example finds an order with a status of pending (Pending) or cancel (Canceled), referencing the following query statement-
SELECT order_id, customer_id, status, TO_CHAR(order_date, ‘YYYY-MM-DD‘) AS order_dateFROM ordersWHERE status = ‘Pending‘ OR status = ‘Canceled‘ORDER BY order_date DESC;
In this example, the statement returns all orders that meet one of the following expressions:
status = ‘Pending‘ -- 或status = ‘Canceled‘
Execute the above query statement to get the following results-
2. Oracle or operator with more than two examples of Boolean expressions
We often use OR operators to combine more than two Boolean expressions. For example, the following statement retrieves an order that is responsible for the following salesperson ID 60 , 61 or 62 :
SELECT order_id, customer_id, status, salesman_id, TO_CHAR(order_date, ‘YYYY-MM-DD‘) AS order_dateFROM ordersWHERE salesman_id = 60 OR salesman_id = 61 OR salesman_id = 62ORDER BY order_date DESC;
Execute the above query statement to get the following results-
You can use the in operator instead of using multiple OR operators, as shown in the following example:
SELECT order_id, customer_id, status, salesman_id, TO_CHAR(order_date, ‘YYYY-MM-DD‘) AS order_dateFROM ordersWHERE salesman_id IN(60, 61, 62)ORDER BY order_date DESC;
The result returned by the query is the same as the OR result returned using the operator above.
3. Examples of using the Oracle or operator in conjunction with the AND operator
You can OR combine operators with other logical operators, such as and and NOT , to form a condition. For example, the following query returns an order that belongs to the customer ID 44 and canceled ( Canceled ) or Pending ( Pending ) status. Refer to the following query statement-
SELECT order_id, customer_id, status, salesman_id, TO_CHAR(order_date, ‘YYYY-MM-DD‘) AS order_dateFROM ordersWHERE ( status = ‘Canceled‘ OR status = ‘Pending‘) AND customer_id = 44ORDER BY order_date;
Execute the above query statement to get the following results-
In this tutorial, you learned how to OR combine two or more Boolean expressions using an Oracle operator.
Oracle or clauses