I am trying to handle the NULL value passed to a parameter.
if param1 = 1,2,3
query returns where param in (1,2,3)
if param = NULL
query returns all values.
I have a split function to implement this CSV passed parameter in a single string.
Can anyone help please ?
here is the query:
Thanks,
if param1 = 1,2,3
query returns where param in (1,2,3)
if param = NULL
query returns all values.
I have a split function to implement this CSV passed parameter in a single string.
Can anyone help please ?
here is the query:
Code:
select distinct a.itemnum,a.Description,a.location,tot_sum,individual_sum,ROUND(to_number(decode(individual_sum,0,0,tot_sum/individual_sum)),2)divid,
(select count(*) from matusetrans where itemnum = a.itemnum and siteid =a.siteid and issuetype = 'ISSUE' and transdate between add_months(sysdate,-1) and sysdate ) l1,
(select count(*) from matusetrans where itemnum = a.itemnum and siteid =a.siteid and issuetype = 'ISSUE' and transdate between add_months(sysdate,-2) and add_months(sysdate,-1) ) l3,
(select count(*) from matusetrans where itemnum = a.itemnum and siteid =a.siteid and issuetype = 'ISSUE' and transdate between add_months(sysdate,-3) and add_months(sysdate,-2)) l6
from
(select itemnum,Description,location,siteid,count(*)individual_sum,
(select count(*) from matusetrans where transdate between add_months(sysdate,-12) and
sysdate and issuetype = 'ISSUE' and (siteid = nvl(:SITEID,siteid))) tot_sum
from matusetrans where transdate between add_months(sysdate,-12)
and sysdate and issuetype = 'ISSUE' and (siteid = nvl(:SITEID,siteid)) group by itemnum,Description,location,siteid) a,
prline b where a.itemnum = b.itemnum
and (b.prnum = nvl(:PRNUM,b.prnum))
and (a.location = nvl(:location,a.location))
and a.siteid = b.siteid
/////////this part return 0 rows/////////////
and a.itemnum in ( case
when :n <> NULL then (select * from table(fnc_split(:n))) end ) and
a.itemnum in (case when :n = NULL then a.itemnum end)