plsql - SELECT Statement within IF statement -
i different result select statement when parameter 0, 1 or 2. not skilled in plsql not sure if code give expected result. if run code "sql statement ignored" on line 3.
begin if (:partype = 1) select * x to_date(date) >= (select to_date(sysdate)from dnv.dual) else select * x to_date(date) <= (select to_date(sysdate)from dnv.dual) end if; end;
this example of select statement. later statement become longer , more complex think shows results trying get.
below copy of entire code because not allowed show has become unreadable:
begin if (:partype = 1) select table1.column1 , table1.column2 , table1.column3 , table1.column4 , table1.column5 , table1.column6 , table1.column7 , table1.column8 , table1.column9 , table1.column10 , table1.column11 , table1.column12 , (select table2.columnx x2 table2 somthing) "something" x1 table1 to_date(date) >= (select to_date(sysdate)from dnv.dual) order columnx else select table1.column1 , table1.column2 , table1.column3 , table1.column4 , table1.column5 , table1.column6 , table1.column7 , table1.column8 , table1.column9 , table1.column10 , table1.column11 , table1.column12 , (select table2.columnx x2 table2 somthing) "something" x1 table1 to_date(date) <= (select to_date(sysdate)from dnv.dual) order columnx end if; end;
i have created new code trying learn how case statement works. might me code above. unfortunately code doesn't work think explanes situation better. in excample use separate table data made up. in cases user2 null user1 filled. want items user2 equals parameter if user2 null , user1 equal paramter still need item apear.
select t1.user1, t1.user2 table t1 (case when t1.user2 null t1.user1 in (:paruser) else t1.user2 in (:paruser) end case)
since relational operator of clause depends on partype, cannot traditional case statement charm here. i'll have resort one:
select * x (to_date(date) >= (select to_date(sysdate)from dnv.dual) , :partype = 1) or (to_date(date) <= (select to_date(sysdate)from dnv.dual) , :partype != 1)
Comments
Post a Comment