Skip to content

Instantly share code, notes, and snippets.

@Jviejo
Created December 30, 2015 12:43
Show Gist options
  • Save Jviejo/96a10337d7cfd8e96b28 to your computer and use it in GitHub Desktop.
Save Jviejo/96a10337d7cfd8e96b28 to your computer and use it in GitHub Desktop.
Transformar un xml en una tabla de objectos
create type t_flavio as object(c1 varchar2(100), c2 number);
create type t_flavio_c as table of t_flavio;
declare
tabla t_flavio_c;
begin
with c1 as
(
select xmlelement("root",
xmlelement("rowset",
xmlelement("row", xmlforest('12' as "c2", 222 as "c3")),
xmlelement("row", xmlforest('12' as "c2", 444 as "c3")),
xmlelement("row", xmlforest('12' as "c2", 555 as "c3")),
xmlelement("row", xmlforest('12' as "c2", 666 as "c3"))
)) x
from dual
)
select t_flavio(c2,c3)
bulk collect into tabla
from c1,xmltable('/root/rowset/row'
passing c1.x columns
c2 varchar2(10) path 'c2',
c3 number path 'c3');
dbms_output.put_line(tabla.count);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment