Moving XML over a DBLink

后端 未结 5 1896
不知归路
不知归路 2021-01-22 17:24

I am trying to move some data over a dblink and one of the columns is an XMLType column. The code looks like this:

begin
    delete from some_schema.some_remote_         


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 18:21

    We get ORA-22804 because every instance of a Type in our Oracle database has an OID, which is unique within the database. We cannot transfer that OID to another database; this has caused me grief before when trying to import schemas which have User-Defined Types. I hadn't realised that it also affected XMLType, but it is an Object so it is not surprising.

    The solution is icky: you will have to unload the XML into text on your local database and then convert it back into XML in the remote database.

    I don't have a distributed DB set-up to test this right now, but if you're lucky it may work:

    INSERT INTO some_schema.some_remote_tab@src_2_trg_dblink(id, code, gen_date, xml_data)
    SELECT id, code, gen_date, xmltype ( xml_data.asClobVal() )
    FROM local_table;
    

    If the asClobVal() method doesn't work you may need to use the SQL function XMLSERIALIZE() instead.

    XMLSerialize(DOCUMENT xml_data AS CLOB) 
    

    If you're really unlucky you won't be able to do this in a single SQL statement, and you'll have to solve it using PL/SQL. To a certain extent this will depend on which version of the database you are using; the more recent the version, the more likely you'll be able to it in SQL rather than PL/SQL.

提交回复
热议问题