sql - Using Column Values from One Table within a Where Clause -
i have oracle table called: col_mapping column in table has column values of columns table.
example data of table: col_mapping
id descr col_vals ------------------------------ 1 label col_1 2 name_addr col_2:col_3 3 salary col4
based on above table, go through each record in col_mapping , use col_vals part of condition in table called other_tab, i.e.:
select 'y' other_tab col_1 = 'whatever1'; select 'y' other_tab (col_2 = 'whatever2' or col_3 = 'whatever2'); , finally: select 'y' other_tab col_4 = 'whatever4';
i split out col_vals condition , there more 1 value colon separated, turn or condition above examples.
any on how achieve above in oracle great.
thanks.
this not tested. how believe can accomplished. need 2 loops. 1 loop through table col_mapping
, other loop through column col_vals
each row , construct condition.
something this:
declare a_where_vars apex_application_global.vc_arr2; --you can replace own associative array here l_where_string varchar2(4000); begin in (select id, descr, col_vals col_mapping) loop a_where_vars := apex_util.string_to_table(i.col_vals, ':') --split values array j in 1 .. a_where_vars.count loop l_where_string := l_where_string||a_where_vars(j)||' = '||whatever_variable||' or '; end loop; --you can remove last or , clean l_where_string --then query: execute immediate := ' select ''y'' other_tab '||l_where_string end loop some_binding_variables; --other queries. end; /
Comments
Post a Comment