This Oracle tutorial explains how to use the Oracle IN condition with syntax and examples.
The Oracle IN condition is used to help reduce the need to use multiple OR conditions in a SELECT, INSERT, UPDATE, or DELETE statement.
The syntax for the IN condition in Oracle/PLSQL is:
OR
The value to test.
The values to test against expression.
This is a SELECT statement whose result set will be tested against expression. If any of these values matches expression, then the IN condition will evaluate to true.
Let's look at an Oracle IN condition example using character values.
The following is an Oracle SELECT statement that uses the IN condition to compare character values:
This Oracle IN condition example would return all rows where the customer_name is either CISCO, Hewlett Packard, or GCP. Because the * is used in the SELECT, all fields from the customers table would appear in the result set.
The above IN example is equivalent to the following SELECT statement:
As you can see, using the Oracle IN condition makes the statement easier to read and more efficient.
Next, let's look at an Oracle IN condition example using numeric values.
For example:
This Oracle IN condition example would return all orders where the order_id is either 10000, 10001, 10003, or 10005.
The above IN example is equivalent to the following SELECT statement:
Finally, let's look at an IN condition example using the Oracle NOT operator.
For example:
This Oracle IN condition example would return all rows where the customer_name is not CISCO, Hewlett Packard, or GCP. Sometimes, it is more efficient to list the values that you do not want, as opposed to the values that you do want.