Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare two CLOB values in Oracle

Tags:

sql

oracle

I have two tables I would like to complare. One of the columns is type CLOB. I would like to do something like this:

select key, clob_value source_table
minus
select key, clob_value target_table

Unfortunately, Oracle can't perform minus operations on clobs. How can I do this?

like image 835
Zach Avatar asked Sep 17 '08 17:09

Zach


People also ask

How do you know if a CLOB is null?

Try this: declare Data1 Clob; begin Data1 := 'ab c d'; -- replace all the whitespace in Data1 with null if dbms_lob. getlength(regexp_replace(Data1,'[[:space:]]'))=0 then dbms_output. put_line('First try: Data1 is null'); else dbms_output.

How many CLOB columns are allowed in a table Oracle?

Only one LONG column is allowed per table.


2 Answers

The format is this:

dbms_lob.compare(  
lob_1    IN BLOB,  
lob_2    IN BLOB,  
amount   IN INTEGER := 18446744073709551615,  
offset_1 IN INTEGER := 1,  
offset_2 IN INTEGER := 1)  
RETURN INTEGER; 

If dbms_lob.compare(lob1, lob2) = 0, they are identical.

Here's an example query based on your example:

Select key, glob_value  
From source_table Left Join target_table  
  On source_table.key = target_table.key  
Where target_table.glob_value is Null  
  Or dbms_lob.compare(source_table.glob_value, target_table.glob_value) <> 0
like image 175
Nick Craver Avatar answered Sep 22 '22 19:09

Nick Craver


Can you access the data via a built in package? If so then perhaps you could write a function that returned a string representation of the data (eg some sort of hash on the data), then you could do

select key, to_hash_str_val(glob_value) from source_table
minus
select key, to_hash_str_val(glob_value) from target_table
like image 33
hamishmcn Avatar answered Sep 22 '22 19:09

hamishmcn