In
is used with list of values
or subqueries
.
You can convert a comma separeted string
into a subquery
, by using the following hack:
SELECT TRIM(REGEXP_SUBSTR(temp, '[^,]+', 1, level))
FROM (SELECT :emp_id temp FROM DUAL)
CONNECT BY level <= REGEXP_COUNT(temp, '[^,]+')
Here the 1,2,3
sting will be converted into subquery
that returns 3
rows.
So, the end result, for your case, could be something like this:
SELECT e.*
FROM employee_detail e
WHERE e.emp_id in (
SELECT decode(:emp_id,null, (select e.emp_id from dual)
,TRIM(REGEXP_SUBSTR(temp, '[^,]+', 1, level)) )
FROM (SELECT :emp_id temp FROM DUAL)
CONNECT BY level <= REGEXP_COUNT(temp, '[^,]+'))
Note that in this case In
will return true
if :emp_id
is null
and this was deliberatly achieved by using decode
function.