SQL Oracle Java JSP JDBC PHP MORE

Oracle IN Operator with Example

In Oracle the IN operator used to compare a column with one or more than one value.

It allows you to specify multiple values in a WHERE clause and retrieve rows that match any of those values in a given column.

It always used with where clause.

Oracle IN Operator Syntax

To add a column in a table, the syntax is

SELECT column1, column2, ...
FROM table_name
WHERE column_name IN (value1, value2, ...);
  • column1, column2, ...: The columns you want to retrieve in the result set.
  • table_name: The name of the table you're querying.
  • column_name: The column you want to compare against the list of values.
  • value1, value2, ...: The list of values to check for in the specified column.
Example

Suppose we have to fetch all record from the user_table where city name is equal to Pune, Mumbai.In this case we have to use IN operator.

Sl No Name City Email ID
1 Virat Delhi virat@gmail.com
2 Sachin Mumbai sachin@gmail.com
3 Dhoni Ranchi dhoni@gmail.com
4 Raina Pune raina@gmail.com
SELECT * FROM Customers WHERE City IN ('Pune', 'Mumbai');

Output

Sl No Name City Email ID
2 Sachin Mumbai sachin@gmail.com
4 Raina Pune raina@gmail.com