Insert XML document to database : Insert « XML « Oracle PL/SQL Tutorial






XMLTYPE has built-in functions to allow us to manipulate the data values being placed into the column defined as SYS.XMLTYPE. Data may be inserted into the table using the sys.xmltype.createxml procedure like this:

SQL>
SQL> --
SQL>
SQL>
SQL>
SQL> CREATE TABLE testxml (id NUMBER(3), dt SYS.XMLTYPE);

Table created.

SQL>
SQL> INSERT INTO testxml VALUES(111,
  2  sys.xmltype.createxml(
  3  '<?xml version="1.0"?>
  4  <customer>
  5  <name>Joe Smith</name>
  6  <title>Mathematician</title>
  7  </customer>'))
  8  /

1 row created.

SQL>
SQL> SET LONG 2000
SQL>
SQL> SELECT *
  2  FROM testxml
  3  /

ID        DT
-------------------
111       <?xml version="1.0"?><customer><name>Joe Smith</name><title>Mathematician</title></customer>


SQL>
SQL> drop table testxml;

Table dropped.








33.2.Insert
33.2.1.Insert XML document to database
33.2.2.XMLTYPE with xml schema
33.2.3.Reference one element