sql - How to declare a bulk collect into when I dont know how many columns I'll get - ORACLE -
i'm creating dynamic query have columns "x , y, z, z1...zn" this:
`type var table of varchar2(4000); tnivel var; t_local_code var; tperm var; tval_perm var; temp1 var; temp2 var; temp3 var; temp4 var; temp5 var; temp6 var; temp7 var; begin vquery:='select z.nivel, y.cod_local_perm, z.permiso,y.valor_permiso valor_perm,'; in 2 .. p_checkboxes.count loop if <> p_checkboxes.last vquery:=vquery||' fun_perm_perm('||p_checkboxes(i)||',c.cod_local_perm ),'; else vquery:=vquery||' fun_perm_perm('||p_checkboxes(i)||',c.cod_local_perm ) '; end if; end loop; (select distinct level nivel,a.cod_master , b.cod_local_perm, lpad(chr(9),level,chr(9)) || replace(replace(replace(a.nom_permiso, '' " '' ,null) ,chr(10),null),chr(13),null) perm '; vquery:=vquery||' table1 a, table2 b b.cod_master_sap = a.cod_master_sap , b.tipo_sap =''sap_viejo'' start a.cod_master_sap_padre null connect prior a.cod_master_sap = a.cod_master_sap_padre ) z, sap_perm_revisar y y.id_det = '||p_checkboxes(1)||' , y.cod_local_perm = z.cod_local_perm order y.cod_local_perm'; end; `
the select example in order show i'll new column depending on checkboxes problem when execute query doing this:
execute immediate vquery bulk collect tnivel, tnivel , tperm, tval_perm, temp1 ... tempn;
-- need declare same quantity of checkboxes select.
please me out.
i agree justin if list of columns has no (reasonable) upper limit.
if defined list if columns , not many of them, try generate sql statement fills list dummy values null.
imagine following 3 cases return 3 columns:
select null, a2, a3 mytable; select a1, a2, a3 mytable; select a1, a2, null mytable;
Comments
Post a Comment