This Oracle tutorial explains how to use the AND condition and the OR condition together in an Oracle query with syntax and examples.
The Oracle AND condition and OR condition can be combined in a SELECT, INSERT, UPDATE, or DELETE statement.
When combining these conditions, it is important to use parentheses so that the database knows what order to evaluate each condition. (Just like when you were learning the order of operations in Math class!)
The syntax for the AND condition and OR condition together in Oracle/PLSQL is:
The conditions that are evaluated to determine if the records will be selected.
Let's look at an example that combines the AND and OR conditions in a SELECT statement.
For example:
This AND & OR example would return all suppliers that reside in the state of California whose supplier_name is CISCO and all suppliers whose supplier_id is less than 5000. The parentheses determine the order that the AND and OR conditions are evaluated. Just like you learned in the order of operations in Math class!
The next example takes a look at a more complex statement.
For example:
This AND & OR example would return all supplier_id values where the supplier_name is CISCO OR the supplier_name is Apple and the state is Florida OR the supplier_name is Best Buy, the status is Active and the state is California.
This next AND & OR example demonstrates how the AND condition and OR condition can be combined in the INSERT statement.
For example:
This Oracle AND and OR example would insert into the suppliers table, all account_no and customer_name records from the customers table whose customer_name is either Apple or Samsung and where the customer_id is greater than 20.
This AND & OR example shows how the AND and OR conditions can be used in the UPDATE statement.
For example:
This Oracle AND & OR condition example would update all supplier_name values in the suppliers table to Samsung where the supplier_name was RIM and resides in either the state of California or Florida.
Finally, this last AND & OR example demonstrates how the AND and OR conditions can be used in the DELETE statement.
For example:
This Oracle AND and OR condition example would delete all records from the suppliers table whose state was Florida and either the product was PC computers or the supplier name was Dell.