简体   繁体   English

是否可以从远程Oracle数据库中读取CLOB?

[英]Is it possible to read a CLOB from a remote Oracle database?

This answer on a question on SO says 关于SO问题的这个答案

... you can read a LONG from a remote database, but you can't read a CLOB ...您可以从远程数据库读取LONG,但无法读取CLOB

I did not find anything about this on the internet, is it true? 我在互联网上没有找到任何关于此的信息,这是真的吗? Any documentation or citings for this will be helpful. 任何文档或引用都会有所帮助。

The answer is correct in a certain context, for simple select statements over a DB link, you'll get this error: 答案在某个上下文中是正确的,对于DB链接上的简单select语句,您将收到以下错误:

ORA-22992 : cannot use LOB locators selected from remote tables. ORA-22992 :不能使用从远程表中选择的LOB定位器。

From the errors manual: 从错误手册:

Cause : A remote LOB column cannot be referenced. 原因 :无法引用远程LOB列。
Action : Remove references to LOBs in remote tables. 操作 :删除对远程表中LOB的引用。

I also had trouble finding definitive documentation on this...but we just ran into the same issue in our data warehouse. 我也很难找到关于此的确切文档...但我们在数据仓库中遇到了同样的问题。 However, there are several work-arounds available, pulling the data over or creating a view for example. 但是,有几种可用的解决方法,例如拉动数据或创建视图

@Peter Ilfrich: Doesn't that throw an exception when trying to access any clobs over 4000 bytes? @Peter Ilfrich:在尝试访问超过4000字节的任何clobs时,是否会抛出异常?

This is a little more convaluted, but it means you can safely pull back small clobs (< 4000) over a dblink. 这是一个更有价值的,但它意味着你可以安全地拉回dblink上的小clobs(<4000)。

select dbms_lob.substr@<link>((select <columnName> from dual@<link>), 4000, 1)  
  from <table>@<link>  
 where dbms_lob.getlength@<link>((select <columnName> from dual@<link>)) <= 4000;  

Reading a CLOB (or a BLOB) over a dblink is possible with this PL/SQL package: 使用此PL / SQL包可以通过dblink读取CLOB(或BLOB):
https://github.com/HowdPrescott/Lob_Over_DBLink https://github.com/HowdPrescott/Lob_Over_DBLink

I had the same trouble yesterday. 我昨天遇到了同样的麻烦。 This is My solution: create a romote view on the romote table, when comes the CLOB cols, use to_char(),such as to_char(col2). 这是我的解决方案:在romote表上创建一个romote视图,当CLOB cols到来时,使用to_char(),例如to_char(col2)。 Then you can select data from the view. 然后,您可以从视图中选择数据。 It may not be a good solution, but it works. 它可能不是一个好的解决方案,但它的工作原理。

If both DB schemes are in the same Oracle instance, you can use the following workaround: 如果两个DB方案都在同一Oracle实例中,则可以使用以下解决方法:

select (select <columnName> from dual) <columnName> from <table>@<link>

This will return you the same as if you would access a local LOB column. 这将返回与访问本地LOB列相同的内容。

Oracle 12.2 finally added support for distributed LOBs . Oracle 12.2最终添加了对分布式LOB的支持。 We can now read data types like CLOB and XMLType over database links without any workarounds. 我们现在可以通过数据库链接读取CLOB和XMLType等数据类型,而无需任何解决方法。

When your table from dblink it's an Oracle Big Data External table (in my case an external table over a Hive table), you need to create a materialized view over it and use that materialized view with the above mentioned pl/sql package: https://github.com/HowdPrescott/Lob_Over_DBLink 当您的表来自dblink时,它是一个Oracle大数据外部表(在我的情况下是一个Hive表上的外部表),您需要在其上创建一个物化视图,并使用上面提到的pl / sql包的物化视图: https: //github.com/HowdPrescott/Lob_Over_DBLink

Works for clobs > 4000. 适用于clobs> 4000。

Tested only for CLOB! 仅针对CLOB进行测试!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM