Build comma separated string in sub query with Case Expression
libranAug 11 2009 — edited Aug 11 2009oracle 10g, on Windows XP
Look at the following query:
select batch_id, state_tag_seq from tr where request_type in ( select case WHEN PX = 'RETURN' THEN 'TRANSFER'||','||'TRANSIT'
WHEN PX = 'RFT' THEN 'TRANSIT'
ELSE 'Invalid'
END
FROM DUAL
) ;
In this case PX is accepted at the runtime from the user interface.
I am having no rows returned (while valid rows matching the criteria exists within DB) for the following case evaluation
WHEN PX = 'RETURN' THEN 'TRANSFER'||','||'TRANSIT' (When PX is evaluated to 'RETURN')
The query works fine WHEN px IS evaluated to 'RFT' (as the evaluated expression is just a single string('TRANSIT'), not separated by commas, like in the other case)
Hiow do I rewrite this query, so it yields the correct result? In other words I am actually building the string within the sub query, which will be evaluated by the outer query's where IN clause.
I am thinking that it could be a specific way of using the quotes in my case expression, but I am reaching a dead end. Any help is appreciated.
Thanks
SR