Possible Duplicate:
How to best split csv strings in oracle 9i
I have some legacy data where there’s a VARCHAR2(100) field SUBID that has comma-delimited data:
empno subid
1 1, 3, 2
2 18,19, 3, 6, 9
etc.
I need to write the equivalent of
select *
from table
where id in ( select SUBID from subidtable where empno = 1 )
Is there a way to accomplish this in Oracle?
Edit:
Added some clarification. I need to do the IN clause against the values stored in a string from a single row, not all rows.
You can, but it’s a little ugly. Depending on the Oracle version
You can use a variant of this askTom thread to parse the data into a collection and use the collection in your SQL statement. This should work in any version of Oracle since 8.1.5 but the syntax has gotten a bit simpler over the years.
You can also use regular expressions as discussed in this StackOverflow thread