oracle - IF ELSE check variable value without needing to define entire resultset -
i have 2 similar queries use work research , trying use boolean variable decide 1 run.
the problem:
in order save variable, think need use pl/sql block, seems require me define every column of resultset , bulk collect resultset. setting template coworkers, of whom know basic sql, can't ask them define new columns.
is there way me allow them set boolean variable , run corresponding sql query outside of pl/sql block? there better way it?
what have far (doesn't work):
declare submit_denied_lines boolean; begin submit_denied_lines := true; --or false depending on needs if submit_denied_lines = false goto qry_status_x; else goto qry_resolution; end if; end; <<qry_status_x>> (the status_x query) goto the_end; <<qry_resolution>> (the resolution query) <<the_end>>
notes:
if asking not possible, post 2 sql files them use , leave notes 1 applies situation.
thank help.
your missing lot of information. same select different criteria? (where clause) or different
this 1 method of doing if different. this runnable
declare submit_denied_lines boolean := true; begin if submit_denied_lines in (select 'status_x' t dual) loop dbms_output.put_line (i.t); end loop; else in (select 'qry_resolution' t dual) loop dbms_output.put_line (i.t); end loop; end if; end;
here 1 if select clause same clause different this runnable
declare submit_denied_lines boolean := true; test char (1); begin /* can't use boolean in sql engine */ if (submit_denied_lines) test := '1'; else test := '0'; end if; in (select * user_objects (user_objects.object_type = 'table' , test = '1') or (user_objects.object_type = 'view' , test = '0')) loop dbms_output.put_line (i.object_name); end loop; end;
Comments
Post a Comment