Can Oracle SQL*Loader process XML?

☆樱花仙子☆ 提交于 2019-12-23 04:14:08

问题


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, could be uploaded back into the table again, by just running sqlldr with appropriate control file contents.
But I cannot find anything about this anywhere on the web, and error messages after trials seem to indicate that it is only possible to upload XML into XML-type formatted tables, where I just want to upload data in a plain table but supply the data in XML format.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/12210944/can-oracle-sqlloader-process-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!