Skip to content
Advertisement

Nvl function with multiple row set in oracle

I have a problem with NVL function in oracle. If I send periods variable as null it is working.There is no data in query.I mean NVL function is working properly. If I send periods variable as for example 10 , it gives error like that

This code block does not work because select query returns more than one row

I tried to use case when in where block but I cannot use it.Do you have any idea?

Advertisement

Answer

You would get the same error if you changed IN to =. IN can handle sets of multiple rows from a subquery, but NVL() and = cannot.

If you INSIST on using NVL, change your subquery to return AT MOST 1 row:

Or if you need multiple rows, rewrite your query to not use NVL:

A modified version of Gordon’s answer from yesterday is another example:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement