In this tutorial, you will learn how to AND
combine two or more Boolean expressions using the Oracle operator.
The Oracle and operator describes
AND
The operator is a logical operator that combines a Boolean expression and returns if all two expressions are true true
. If one of the expressions is false, the AND
operator returns false
.
AND
The syntax of the operator is as follows:
expression_1 AND expression_2
The following table describes the AND
true
results of using an operation that conforms to and, false
and NULL
values-
value |
TRUE |
FALSE |
NULL |
TRUE |
TRUE |
FALSE |
Null |
FALSE |
FALSE |
FALSE |
FALSE |
Null |
Null |
FALSE |
Null |
Typically, the criteria used in the WHERE clause of the SELECT,DELETE and UPDATE statements AND
to form matching data. In addition, the operator is used in the predicate of the join clause AND
to form the join condition.
When using more than one logical operator in a declaration, Oracle always evaluates the AND
operator first. However, you can use parentheses to change the order of evaluations.
Examples of Oracle and operators
See the following order () table in the sample database orders
:
1. Oracle
AND
Example of a combination of two Boolean expressions
The following example finds the orders with the customer number as 2
pending ( Pending
):
SELECT order_id, customer_id, status, TO_CHAR(order_date,‘YYYY-MM-DD‘) AS order_dateFROM ordersWHERE status = ‘Pending‘ AND customer_id = 2ORDER BY order_date;
In this example, the query returns all the order information that satisfies both expressions, namely:
status = ‘Pending‘
And
customer_id = 2
Execute the above query statement to get the following result:
2. Oracle and the example of combining more than two Boolean expressions
You can use multiple AND
operators to combine Boolean expressions.
For example, the following statement retrieves an order that meets all of the following conditions:
- Placed in the
2017
year.
- Responsible for the salesperson number
60
.
- There is a delivery status.
Refer to the following query statement-
SELECT order_id, customer_id, status, TO_CHAR(order_date, ‘YYYY-MM-DD‘) AS order_dateFROM ordersWHERE status = ‘Shipped‘ AND salesman_id = 60 AND EXTRACT(YEAR FROM order_date) = 2017ORDER BY order_date;
Execute the above query statement to get the following results-
3. Examples of Oracle and and or operators combined
You can AND
combine operators with other logical operators, such as OR and NOT
, to form a condition.
For example, the following query ID
finds 44
an order for the customer, and the status is canceled (Canceled) or pending (Pending). Refer to the following implementation 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, we have learned how to use AND
the Oracle operator to combine two or more Boolean expressions.
Oracle and clauses