Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This answer on a question on SO says

... you can read a LONG from a remote database, but you can't read a CLOB

I did not find anything about this on the internet, is it true? Any documentation or citings for this will be helpful.

like image 362
Moeb Avatar asked Aug 29 '10 11:08

Moeb


People also ask

How do I search CLOB data?

CLOBs require that you use the DBMS_LOB package to perform substr/instr type searches. In order to use do any kind of searching within the column, you must first get the locator for the CLOB column, the use the DBMS_LOB. SUBSTR or DBMS_LOB. INSTR function to search and/or pull part of the text from the string.

How do you get CLOB in Toad?

If you want to enable clob previews, go to View > TOAD Options > Data Grids > Data > check the "Preview CLOB and LONG data" box.

How does Oracle handle CLOB data types?

In Oracle, you can use LENGTH() or DBMS_LOB. GETLENGTH() function to get the length of a CLOB column in characters. There is LENGTHB() function to get the length in bytes, but it can be used for single-byte CLOBs only, so it will return the same result as LENGTH().


2 Answers

The answer is correct in a certain context, for simple select statements over a DB link, you'll get this error:

ORA-22992: cannot use LOB locators selected from remote tables.

From the errors manual:

Cause: A remote LOB column cannot be referenced.
Action: Remove references to LOBs in remote tables.

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.

like image 123
Nick Craver Avatar answered Sep 28 '22 04:09

Nick Craver


@Peter Ilfrich: Doesn't that throw an exception when trying to access any clobs over 4000 bytes?

This is a little more convaluted, but it means you can safely pull back small clobs (< 4000) over a dblink.

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:
https://github.com/HowdPrescott/Lob_Over_DBLink

like image 41
Howd Avatar answered Sep 28 '22 05:09

Howd