Does Oracle offer a standardized upload of XML formatted files?
I thought that the canonical format that is used for XML output, structure = ROWSET/ROW/columname
There isn't a standardised option, but with this specific format you can do it. If you have a table:
CREATE TABLE test_tab (
id NUMBER,
text VARCHAR2(50)
);
And your records in a test_tab.xml
file:
<ROWSET>
<ROW>
<ID>1</ID>
<TEXT>This is some text</TEXT>
</ROW>
<ROW>
<ID>2</ID>
<TEXT>This is some more text</TEXT>
</ROW>
<ROW>
<ID>3</ID>
<TEXT>This is some other text</TEXT>
</ROW>
<ROW>
<ID>4</ID>
<TEXT>This is also some text</TEXT>
</ROW>
</ROWSET>
And a control file test_tab.ctl
:
LOAD DATA
INFILE 'test_tab.xml'
CONCATENATE 4
INTO TABLE test_tab
(
dummy FILLER CHAR(15) TERMINATED BY "<ROW>",
id CHAR(10) ENCLOSED BY "<ID>" AND "</ID>",
text CHAR(40) ENCLOSED BY "<TEXT>" AND "</TEXT>"
)
You can do:
sqlldr usr/pwd control=test_tab.ctl
Commit point reached - logical record count 4
SELECT * FROM test_tab;
ID TEXT
---------- --------------------------------------------------
1 This is some text
2 This is some more text
3 This is some other text
4 This is also some text
You could also create an external table from the same file, if you put in a directory Oracle can see:
CREATE TABLE test_tab (
id NUMBER,
text VARCHAR2(50)
)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_LOADER
DEFAULT DIRECTORY some_dir
ACCESS PARAMETERS
(
RECORDS DELIMITED BY "</ROW>"
FIELDS
(
dummy CHAR(15) TERMINATED BY "<ROW>",
id CHAR(10) ENCLOSED BY "<ID>" AND "</ID>",
text CHAR(40) ENCLOSED BY "<TEXT>" AND "</TEXT>"
)
)
LOCATION ('test_tab.xml')
)
PARALLEL
REJECT LIMIT UNLIMITED;
Table created.
SELECT * FROM test_tab;
ID TEXT
---------- --------------------------------------------------
1 This is some text
2 This is some more text
3 This is some other text
4 This is also some text
No, SQL*Loader can only process "flat" files.
One option is to write an XSLT transformation that turns the ROWSET/ROW/column
format into a text file and then import that into the target table.
Another option is to import the XML into a single row, and then use Oracle's XML functions to select a relational result from that staging table and insert it into the real table.