As of Oracle Database 10g, the XMLTYPE
clause is available for use in a SQL*Loader control file. This clause is of the format XMLTYPE(field name)
. It is used to identify XMLType
tables so that the correct SQL statement can be constructed. Example 9-2 shows how the XMLTYPE
clause can be used in a SQL*Loader control file to load data into a schema-based XMLType
table.
Oracle XML DB Developer's Guide for more information about loading XML data using SQL*Loader
Example 9-2 Identifying XMLType Tables in the SQL*Loader Control File
The XML schema definition is as follows. It registers the XML schema, xdb_user.xsd
, in the Oracle XML DB, and then creates the table, xdb_tab5
.
begin dbms_xmlschema.registerSchema('xdb_user.xsd', '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb"> <xs:element name = "Employee" xdb:defaultTable="EMP31B_TAB"> <xs:complexType> <xs:sequence> <xs:element name = "EmployeeId" type = "xs:positiveInteger"/> <xs:element name = "Name" type = "xs:string"/> <xs:element name = "Salary" type = "xs:positiveInteger"/> <xs:element name = "DeptId" type = "xs:positiveInteger" xdb:SQLName="DEPTID"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>', TRUE, TRUE, FALSE); end; /
The table is defined as follows:
CREATE TABLE xdb_tab5 OF XMLTYPE XMLSCHEMA "xdb_user.xsd" ELEMENT "Employee";
The control file used to load data into the table, xdb_tab5
, looks as follows. It loads XMLType
data using the registered XML schema, xdb_user.xsd
. The XMLTYPE
clause is used to identify this table as an XMLType
table. Either direct path or conventional mode can be used to load the data into the table.
LOAD DATA INFILE * INTO TABLE xdb_tab5 TRUNCATE xmltype(xmldata) ( xmldata char(4000) ) BEGINDATA <Employee> <EmployeeId>111</EmployeeId> <Name>Ravi</Name> <Salary>100000</Sal ary> <DeptId>12</DeptId></Employee> <Employee> <EmployeeId>112</EmployeeId> <Name>John</Name> <Salary>150000</Sal ary> <DeptId>12</DeptId></Employee> <Employee> <EmployeeId>113</EmployeeId> <Name>Michael</Name> <Salary>75000</S alary> <DeptId>12</DeptId></Employee> <Employee> <EmployeeId>114</EmployeeId> <Name>Mark</Name> <Salary>125000</Sal ary> <DeptId>16</DeptId></Employee> <Employee> <EmployeeId>115</EmployeeId> <Name>Aaron</Name> <Salary>600000</Sa lary> <DeptId>16</DeptId></Employee>