Best way to use variables that contain lists in Oracle SQL -
i have around 5 long sql queries , replace of values variables, can enter them directly in script @ top (no pop ups).
what best way achieve (and comes part makes question not duplicate), can have variables lists. example here how queries should differ between configuration 1 , 2:
where trd_src_sys ='blabla1' trd_src_sys ='blabla223' select 'blabla1- new' rec_system, select 'blabla223- new' rec_system, trd_src_sys in ('mag','llelle') trd_src_sys ='ma'
independent of set date in 1 place, don't have change everywhere occurs in query. (but believe explained in other posts)
any suggestions appreciated.
you can use substitution variables like:
define sys_list = "'mag','llelle'"
then write query like:
... trd_src_sys in (&sys_list.)
it resolve to:
... trd_src_sys in ('mag','llelle')
when need 1 value:
define sys_list = "'ma'"
... query resolve to
... trd_sys in ('ma')
which means same
... trd_sys = 'ma'
script example
sql> select * t1; trd_src_sys ------------------------------ ma mag llelle
create script called script.sql contents:
select * t1 trd_src_sys in (&1.);
run script different parameters:
sql> @script "'ma'" old 1: select * t1 trd_src_sys in (&1.) new 1: select * t1 trd_src_sys in ('ma') trd_src_sys ------------------------------ ma sql> @script "'mag','llelle'" old 1: select * t1 trd_src_sys in (&1.) new 1: select * t1 trd_src_sys in ('mag','llelle') trd_src_sys ------------------------------ mag llelle
Comments
Post a Comment