Connor and Chris will both be at AI World from October 12 to October 17 , the premier Oracle conference of 2025. If you're in Vegas, please come say Hi or pop into our sessions
Thanks for the question, Michael.
Asked: January 23, 2018 - 4:25 pm UTC
Last updated: January 25, 2018 - 1:48 am UTC
Version: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
Viewed 10K+ times! This question is
SQL> with emp as ( select 123 empno, 'O''Brien' ename from dual ) 2 select 3 xmlelement("blah", 4 xmlforest(e.empno as "empid", 5 e.ename as "name") 6 ) 7 from emp e; XMLELEMENT("BLAH",XMLFOREST(E.EMPNOAS"EMPID",E.ENAMEAS"NAME")) ------------------------------------------------------------------------------------------ <blah><empid>123</empid><name>O'Brien</name></blah> SQL> SQL> set serverout on SQL> declare 2 x xmltype; 3 new_x xmltype; 4 begin 5 with emp as ( select 123 empno, 'O''Brien' ename from dual ) 6 select 7 xmlelement("blah", 8 xmlforest(e.empno as "empid", 9 e.ename as "name") 10 ) 11 into x 12 from emp e; 13 14 dbms_output.put_line(x.getClobVal()); 15 new_x := xmltype(dbms_xmlgen.convert(x.getClobVal(), dbms_xmlgen.ENTITY_DECODE)); 16 dbms_output.put_line(new_x.getClobVal()); 17 18 end; 19 / <blah><empid>123</empid><name>O'Brien</name></blah> <blah><empid>123</empid><name>O'Brien</name></blah> PL/SQL procedure successfully completed.
Michael Kemp, January 24, 2018 - 5:15 pm UTC
New to good database design? Check out Chris Saxon's full fundamentals class.