Skip to Main Content
  • Questions
  • How to concatenate 2 xmltype records into one record

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Mona.

Asked: March 08, 2018 - 9:32 pm UTC

Last updated: March 09, 2018 - 3:04 am UTC

Version: Oracle 12C

Viewed 1000+ times

You Asked

Hi,

I have a requirement of concatenating 6 different xml files stored in a table and passing it to another procedure as a single file as an input.

The column datatype holding the xml is XMLTYPE.


Thanks,
Mona

and Connor said...

Something like this ?

SQL> create table t ( x xmltype );

Table created.

SQL>
SQL> begin
  2    insert into t values (
  3      xmltype.createxml('<departments>
  4          <dept>
  5            <deptno>123</deptno>
  6            <dname>My Department</dname>
  7          </dept>
  8        </departments>'));
  9
 10    insert into t values (
 11      xmltype.CREATEXML(
 12       '<emp>
 13          <empno>456</empno>
 14          <ename>John Smith</ename>
 15        </emp>'));
 16  end;
 17  /

PL/SQL procedure successfully completed.

SQL>
SQL> select xmlelement("MERGED", XMLAGG(x)) from t;

XMLELEMENT("MERGED",XMLAGG(X))
-----------------------------------------------------------
<MERGED><departments>
  <dept>
    <deptno>123</deptno>
    <dname>My Department</dname>
  </dept>
</departments><emp>
  <empno>456</empno>
  <ename>John Smith</ename>
</emp>
</MERGED>



Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.