Split comma separated string and pass to IN clause of select statement in Oracle
1. Example
In some situations you have a String, for example:
'KING,JONES,FORD'
You want to turn it into a Select statement and returns results like the illustration below:
With Oracle > 9, you can write SQL:
-- ORACLE > 9.x
Select Regexp_Substr('KING,JONES,FORD'
,'[^,]+'
,1
,Level) Emp_Name
From Dual
Connect By Regexp_Substr('KING,JONES,FORD'
,'[^,]+'
,1
,Level) Is Not Null;
Find the employees named in a String separated by commas.
Select * From Employee Emp
Where
Emp.Emp_Name In ('KING','JONES','FORD');
You need to combine two nested statement:
Select *
From Employee Emp
Where Emp.Emp_Name In
(Select Regexp_Substr('KING,JONES,FORD'
,'[^,]+'
,1
,Level) Emp_Name
From Dual
Connect By Regexp_Substr('KING,JONES,FORD'
,'[^,]+'
,1
,Level) Is Not Null);
Results of running the statement:
Oracle Database Tutorials
- Install PL/SQL Developer on Windows
- Sample Oracle Database for Learning SQL
- SQL Tutorial for Beginners with Oracle
- Install Oracle Database 11g on Windows
- Install Oracle Database 12c on Windows
- Install Oracle Client on Windows
- Create Oracle SCOTT Schema
- Sample Database
- Database structure and Cloud features in Oracle 12c
- Importing and Exporting Oracle Database
- Oracle String functions
- Split comma separated string and pass to IN clause of select statement in Oracle
- Hierarchical Queries in Oracle
- Oracle Database Link and Synonym Tutorial with Examples
- Oracle PL/SQL Programming Tutorial with Examples
- XML Parser for Oracle PL/SQL
- Standard Database Auditing in Oracle
- Creating and Managing Oracle Wallet
Show More