sql - Oracle Select query dynamic parameter condition -
sql - Oracle Select query dynamic parameter condition -
help me write select query
i have 3 tables follows
subscriber ############################ subscr_id parent id --------- --------- 1 100 2 100 3 101 4 101
so there can more 1 subscr_id under 1 parent id (these called locations). other tables are
products ############################ subscr_id products businessline --------- -------- ------------- 1 5100 100 1 1100 200 2 3100 300
and
addons ############################ subscr_id products businessline addons --------- --------- ------------ ------ 1 5100 100 1 1 5100 100 5 1 5100 100 30 1 1100 200 5 1 1100 200 25
now have 4 parameters -1) products 2) businessline 3) addons 4) parent id users give. none of 1,2,3 mandatory.
for input parent id output true else false based on next conditions
if product given result true if 1 of locations of parent have entries products = given product input if business given result true if 1 of locations of parent have entries businessline = given business line if both business , product given result true if 1 of locations of parent have entries businessline = given business line , product = given product if addons given result true if 1 of locations of parent have entries addons = given addon in addons tables numerous conditions possiblei want write single select query
i had tried in local database based on on data. procedure follows in next procedure used notations are
subscr_id sid parent id pid businessline blproducts pro
declare given_pro number(5):=&given_pro; given_bl number(5):=&given_bl; given_addons number(5):=&given_addons; cursor cur select distinct s.pid subscriber s,product p,addons (nvl(given_pro,1)=given_pro , nvl(given_bl,1)=1 , s.sid=p.sid , a.pro=given_pro , p.pro=given_pro , a.pro=p.pro , a.sid=s.sid , p.sid=a.sid) or (nvl(given_bl,1)=given_bl , nvl(given_pro,1)=1 , a.bl=given_bl , p.bl=given_bl , s.sid=p.sid , a.bl=p.bl , a.sid=s.sid , p.sid=a.sid) or (nvl(given_bl,1)=given_bl , nvl(given_pro,1)=given_pro , a.pro=given_pro , p.pro=given_pro , a.bl=given_bl , p.bl=given_bl , s.sid=p.sid , a.pro=p.pro , a.bl=p.bl , a.sid=s.sid , p.sid=a.sid) or (nvl(given_addons,1)=given_addons , nvl(given_bl,1)=1 , nvl(given_pro,1)=1 , a.sid=s.sid); rec cur%rowtype; begin open cur; loop fetch cur rec; exit when cur%notfound; dbms_output.put_line(rec.pid ||' hello'); end loop; close cur; end;
this procedure give pid
sql oracle plsql
Comments
Post a Comment