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!

NVL with multiple row subquery

oramanNov 9 2011 — edited Nov 9 2011
Hi SQL-gurus,

I try to build a query for two tables with 1:n relation. bericht (b_id is primary key) is 1 and ueber_produkt (b_id is foreign key) is n.

the query should return all rows from bericht in case :P15_PROD is null and all the matching rows in the other case.

so far it looks like this:

this attempt returns a good result but in case :P15_PROD is null this query returns only b_id's from bericht which are equal to b_id's in ueber_produkt, however I would like to return all b_id's from bericht. -->

select b.b_id,b.m_id,b.text,b.zeitaufwand,b.datum,b.kw_id
from bericht b
where b.b_id in (select distinct b_id from ueber_produkt where produktname in nvl(:P15_PROD, produktname))


this one returns error "ORA-01427: single-row subquery returns more than one row" -->

select b.b_id,b.m_id,b.text,b.zeitaufwand,b.datum,b.kw_id
from bericht b
where b.b_id in nvl( (select distinct b_id from ueber_produkt where produktname in :P15_PROD), b.b_id )

Why is it a single row subquery? I use IN operator fro multiple row subqueries!


I hope I explained it well.

Any help would be appreciated
This post has been answered by Frank Kulash on Nov 9 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 7 2011
Added on Nov 9 2011
3 comments
3,439 views