This article is written about how to use the Oracle OR condition with syntax and examples.
The Oracle OR circumstance is used to check more than one conditions where data are returned when any one of the stipulations are met. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.
The syntax for the OR condition in Oracle/PLSQL is:
WHERE condition1 OR condition2 ... OR condition_n;
Parameters or Arguments
condition1, condition2, condition_n Any of the conditions can be met for the documents to be selected.
The Oracle OR situation permits you to take a look at two or more conditions. The Oracle OR condition requires that any of the stipulations (ie: condition1, condition2, condition_n) ought to be met for the report to be protected in the end result set.
Example – With SELECT Statement
The first Oracle OR situation example that we will take a appear at entails an Oracle SELECT announcement with two conditions:
SELECT * FROM customers WHERE state = 'California' OR available_credit > 500;
This Oracle OR circumstance instance would return all customers that dwell in either the country of California or have available_credit higher than 500 Because the * is used in the SELECT statement, all fields from the customers desk would show up in the result set.
Example – With SELECT Statement (3 conditions)
The subsequent Oracle OR instance appears at an Oracle SELECT assertion with 3 conditions. If any of these stipulations is met, the file will be blanketed in the end result set.
SELECT supplier_id FROM suppliers WHERE supplier_name = 'IBM' OR city = 'New York' OR offices > 5;
This Oracle OR situation example would return all supplier_id values the place the supplier’s title is both IBM, city is New York, or workplaces is larger than 5.
Example – With INSERT Statement
The Oracle OR condition can be used in the Oracle INSERT statement.
INSERT INTO suppliers (supplier_id, supplier_name) SELECT account_no, name FROM customers WHERE city = 'New York' OR city = 'Newark';
This Oracle OR instance would insert into the suppliers table, all account_no and identify information from the clients table that live in both New York or Newark.
Example – With UPDATE Statement
The Oracle OR circumstance can be used in the Oracle UPDATE statement.
UPDATE suppliers SET supplier_name = 'Apple' WHERE supplier_name = 'RIM' OR available_products < 10;
This Oracle OR condition instance would update all supplier_name values in the suppliers table to Apple where the supplier_name used to be RIM or its availabe_products used to be much less than 10.
Example – With DELETE Statement
The Oracle OR circumstance can be used in the Oracle DELETE statement.
DELETE FROM suppliers WHERE supplier_name = 'HP' OR employees >= 60;
This Oracle OR circumstance instance would delete all suppliers from the suppliers desk whose supplier_name was HP or its personnel was increased than or equal to 60.