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
single-row-subquery-returns-more-than-one
This code block does not work because select query returns more than one row
Select ....... FROM students st, orders od
WHERE st.id IN NVL((select id from students
where student_id = 321
ORDER BY id desc
FETCH FIRST periods ROWS ONLY),(od.countNo))
I tried to use case when in where block but I cannot use it.Do you have any idea?
You would get the same error if you changed
IN
to=
.IN
can handle sets of multiple rows from a subquery, butNVL()
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: