Search code examples
sqlxmloracle-databaseplsqlobject-oriented-database

Transfer data from table into XML object table


If I have a table:

create table thisTable (
    column1 varchar(20),
    column2 varchar(20),
    column3 varchar(20)
);

and I want to transfer data to a 1 column XML table:

create table XMLTable (
    data1 sys.xmltype
);

<column2>
    <column1>..</column1>
    <column2>..</column2>
    <column3>..</column3>
</column2>

How would I do that?


Solution

  • INSERT INTO XMLTABLE
    SELECT
        XMLELEMENT(
            "column2",
            XMLELEMENT("column1", COLUMN1), XMLELEMENT("column2", COLUMN2), XMLELEMENT("column3", COLUMN3)
        )
    FROM
        thisTable;