Loading XML documents into an Oracle database (2)

If only I could do the following…(but it seems that it isn’t supported yet)…

That is…based on the first “Loading XML documents into an Oracle database (1)” post…

…build an XMLTYPE VIEW with an instead trigger moving the XML document REFERENCE values in one go in the varchar2() REFERENCE column, while inserting the XML document content in the XMLType column XML_VALUE…

 
SQL> -- while using the following sampleData.ctl SQL Loader control file
 
SQL> host cat sampleData.ctl
 
LOAD DATA
INFILE 'sampleData.dat'
append
INTO TABLE XML_VIEW
xmltype(XMLDATA) (
 filename filler CHAR(120),
 XMLDATA  lobfile(filename) TERMINATED BY eof)
 
SQL> CREATE TABLE RELATIONAL_TABLE (
  2  	REFERENCE  VARCHAR2(100),
  3  	XML_VALUE  XMLTYPE
  4  )
  5  /
 
TABLE created.
 
Elapsed: 00:00:01.69
 
SQL> CREATE OR REPLACE VIEW XML_VIEW OF xmltype
  2  WITH object id (
  3    xmlcast(XMLQuery('$X/PurchaseOrder/Reference' passing OBJECT_VALUE AS "X" returning content) AS varchar2(100))
  4  )
  5  AS
  6  SELECT XML_VALUE
  7    FROM RELATIONAL_TABLE
  8  /
 
VIEW created.
 
Elapsed: 00:00:00.17
 
SQL> CREATE OR REPLACE TRIGGER DATA_LOADER
  2  instead OF INSERT ON XML_VIEW
  3  BEGIN
  4  	     INSERT INTO RELATIONAL_TABLE VALUES (
  5  	       XMLCAST(
  6  		 XMLQUERY(
  7  		   '/PurchaseOrder/Reference'
  8  		   passing :NEW.OBJECT_VALUE
  9  		   returning CONTENT
 10  		 )
 11  		 AS VARCHAR2(100)
 12  	       ),
 13  	       :NEW.OBJECT_VALUE
 14    );
 15  END;
 16  /
 
TRIGGER created.
 
Elapsed: 00:00:00.07
 
SQL> host sqlldr &USERNAME/&PASSWORD@&TNSALIAS control=sampleData.ctl
 
SQL*Loader: Release 12.1.0.1.0 - Production ON Fri Jul 18 16:55:21 2014
 
Copyright (c) 1982, 2013, Oracle AND/OR its affiliates.  ALL rights reserved.
 
Path used:      Conventional
SQL*Loader-485: TABLE XML_VIEW may NOT be loaded USING a subtype
 
SQL> GET sampleData.log
  1  SQL*Loader: Release 12.1.0.1.0 - Production ON Fri Jul 18 16:55:21 2014
  2  Copyright (c) 1982, 2013, Oracle AND/OR its affiliates.  ALL rights reserved.
  3  Control File:   sampleData.ctl
  4  DATA File:      sampleData.dat
  5    Bad File:     sampleData.bad
  6    Discard File:  NONE specified
  7   (Allow ALL discards)
  8  NUMBER TO LOAD: ALL
  9  NUMBER TO skip: 0
 10  Errors allowed: 50
 11  Bind array:     64 ROWS, maximum OF 256000 bytes
 12  Continuation:    NONE specified
 13  Path used:      Conventional
 14  TABLE XML_VIEW, loaded FROM every logical record.
 15  INSERT OPTION IN effect FOR this TABLE: APPEND
 16	COLUMN Name		     POSITION	Len  Term Encl Datatype
 17  ------------------------------ ---------- ----- ---- ---- ---------------------
 18  FILENAME				 FIRST	 120	       CHARACTER
 19    (FILLER FIELD)
 20  XMLDATA			       DERIVED	   *  EOF      CHARACTER
 21	 Dynamic LOBFILE.  Filename IN FIELD FILENAME
 22* SQL*Loader-485: TABLE XML_VIEW may NOT be loaded USING a subtype
 23  .
 
SQL> SELECT REFERENCE
  2    FROM RELATIONAL_TABLE
  3  /
 
no ROWS selected
 
Elapsed: 00:00:00.02

Alas…”SQL*Loader-485: table XML_VIEW may not be loaded using a subtype”