What i need
- i need to create dynamic sql based on param procedure receives.
Type :[A,B,C]
Code : [1,2,3]
Dynamic sql
AND ( (in_type = 'A' and in_code = '1' )
OR (in_type = 'B' and in_code = '2')
OR (in_type = 'C' and in_code = '3')
)
Solution i tried
splitting string from comma separated
CREATE OR REPLACE TYPE t_my_list AS TABLE OF VARCHAR2(100); CREATE OR REPLACE FUNCTION comma_to_table(p_list IN VARCHAR2) RETURN t_my_list AS l_string VARCHAR2(32767) := p_list || ','; l_comma_index PLS_INTEGER; l_index PLS_INTEGER := 1; l_tab t_my_list := t_my_list(); BEGIN LOOP l_comma_index := INSTR(l_string, ',', l_index); EXIT WHEN l_comma_index = 0; l_tab.EXTEND; l_tab(l_tab.COUNT) := TRIM(SUBSTR(l_string,l_index,l_comma_index - l_index)); l_index := l_comma_index + 1; END LOOP; RETURN l_tab; END comma_to_table;
/
FOR x IN (select * from (table(comma_to_table(in_type)) ) )
LOOP
dbms_output.put_line(x.COLUMN_VALUE);
FOR y IN (select * from (table(comma_to_table(in_code )) ) )
LOOP
dbms_output.put_line(y.COLUMN_VALUE);
IF x.COLUMN_VALUE = 'A' THEN
l_where := l_where||' AND UPPER(column_name) IN (' || upper(in_code) || ')';
END IF;
END LOOP;
END LOOP;