Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Build comma separated string in sub query with Case Expression

libranAug 11 2009 — edited Aug 11 2009
oracle 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
This post has been answered by MichaelS on Aug 11 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 8 2009
Added on Aug 11 2009
5 comments
1,543 views