通过 DBLink 移动 XML
我正在尝试通过 dblink 移动一些数据,其中一列是 XMLType 列。代码如下所示:
begin
delete from some_schema.some_remote_tab@src_2_trg_dblink;
INSERT INTO some_schema.some_remote_tab@src_2_trg_dblink(id, code, gen_date, xml_data)
SELECT id, code, gen_date, xml_data
FROM local_table;
end;
Oracle 返回这些错误:
ORA-02055: distributed update operation failed; rollback required ORA-22804: remote operations not permitted on object tables or user-defined type columns
对 ORA-22804 的一些研究表明,我可能由于 XMLType 列而收到此错误,但我不确定如何解决此问题。
(甲骨文10g)
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_tab@src_2_trg_dblink;
INSERT INTO some_schema.some_remote_tab@src_2_trg_dblink(id, code, gen_date, xml_data)
SELECT id, code, gen_date, xml_data
FROM local_table;
end;
Oracle returns these errors:
ORA-02055: distributed update operation failed; rollback required ORA-22804: remote operations not permitted on object tables or user-defined type columns
Some research on ORA-22804 shows that I am probably getting this error because of the XMLType column, but I am not sure how to resolve this.
(Oracle 10g)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我们得到 ORA-22804 是因为 Oracle 数据库中类型的每个实例都有一个 OID,该 OID 在数据库中是唯一的。我们无法将该 OID 传输到另一个数据库;之前在尝试导入具有用户定义类型的模式时,这让我感到悲伤。我没有意识到它也影响了 XMLType,但它是一个对象,所以这并不奇怪。
解决方案很棘手:您必须将 XML 卸载为本地数据库上的文本,然后将其转换回远程数据库中的 XML。
我现在没有分布式数据库设置来测试这个,但如果你幸运的话它可能会起作用:
如果
asClobVal()
方法不起作用,你可能需要使用改为 SQL 函数 XMLSERIALIZE()。如果您真的很不幸,您将无法在单个 SQL 语句中完成此操作,并且您必须使用 PL/SQL 来解决它。在某种程度上,这取决于您使用的数据库版本;版本越新,您就越有可能在 SQL 而不是 PL/SQL 中使用它。
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:
If the
asClobVal()
method doesn't work you may need to use the SQL function XMLSERIALIZE() instead.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.
尝试以相反的方式进行此操作。即登录到远程数据库,创建到本地数据库的数据库链接,然后执行如下插入
Try to do this the other way around. That is log into the remote db, create a dblink to the local db, and do an insert like this
而是执行数据拉取。
(同时..等待oracle找到一些解决方案来在将来通过dblink执行XML的PUSH)
在远程站点数据库B创建一个过程
从数据库A调用该过程
Instead Perform a Data PULL.
(Meanwhile .. wait for oracle to find some solution to perform the PUSH of XML over dblink in the future)
Create a procedure at Remote site Database B
Call the procedure from Database A
我在连接到 SQL Server 的异构数据库链接时遇到了同样的问题。
由于数据少于 4000 个字符,最终使用 xmltype.getStringVal() 插入 SQL Server 端的 VARCHAR 列。
如果超过 4000 个字符,还有
xmltype.getClobVal()
但我还没有测试过。I was facing the same issue with an heterogeneous DB link to SQL server.
Ended up using
xmltype.getStringVal()
to insert in a VARCHAR column on SQL Server side as the data was under 4000 characters.There is also
xmltype.getClobVal()
if over 4000 characters but I haven't tested it."xml->text->xml" 链可能很复杂,但在某些情况下可能会有所帮助(例如,当不能选择插入而只能更新时)。
您可以尝试使用“n”个 varchar 列(在目标表中或在不同的表中,可能在远程数据库上的不同架构中),其中“n”是:
ceil(max(dbms_lob.getlength(MyXmlColumn)) / 4000)
然后您可以将这些片段传输到远程临时字段:
XmlType 可以从片段重新组合,如下所示:
最后使用结果更新任何remothe 模式中的其他表如:
The "xml->text->xml" chain might be complicated, but could help in some cases (for example when inserting is not on option but updating only).
You can try with "n" peaces of varchar columns (in the destination table or in a differnet one, perheaps in different schema on the remote DB), where "n" is:
ceil(max(dbms_lob.getlength(MyXmlColumn)) / 4000)
Then you can transfer these fragments to remote temporary fields:
XmlType can be re-composed from fragments like this:
Finally use the result to update any other table in the remothe schema like: