Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Samby.

Asked: November 29, 2016 - 5:23 pm UTC

Last updated: December 01, 2016 - 12:52 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi Team

We have migrated data from SQL server to Oracle,As part of data validation we want to compare the data from both databases. We have some tools which compare data but that tool will not compare lob columns.
Please note we had migrated data using SQL developer tool.


Kindly suggest us how to compare image vs blob and varchar(max) vs blob data type . If you aware about some tool which has this functionality kindly share the name. We try using DBMS_lob.compare but here two db are different.so we unable to compare

Kindly suggest

and Connor said...

I dont know much about SQL Server :-) but a google search suggests there is a hash function which implements the standard hashing routines

https://msdn.microsoft.com/en-us/library/ms174415.aspx

and we have DBMS_CRYPTO.

So perhaps take MD5 hashes of the blob/clob content in each database, and compare using that ?

Hope this helps.

Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Sambhav Singh, November 30, 2016 - 8:39 am UTC

Hi, Thanks for your help.

MD5 hash value is different from both database.
So i think this approach will not work.

Kindly suggest i there any other alternative
Chris Saxon
November 30, 2016 - 10:47 am UTC

Are you sure the columns contain the same value? Have you tried any of the other hashes?

Try SH1

Robert Massey, November 30, 2016 - 11:22 am UTC

I had to do something similar. I found that SH1 worked. Here's an example for hashing 'abc'.

In SQL Server:

select convert(varchar(max), hashbytes('sha1', 'abc'), 2)


In Oracle:

select rawtohex(dbms_crypto.hash(utl_raw.cast_to_raw('abc'), 3)) from dual;


'3' corresponds to dbms_crypto.hash_sh1. If you are using the function in a procedure, you can do this:

declare
  sh1   varchar2(40);
begin
  select rawtohex(dbms_crypto.hash(utl_raw.cast_to_raw('abc'), dbms_crypto.hash_sh1)) 
  into sh1
  from dual;
  dbms_output.put_line(sh1);
end;
/


All these should produce the same hash: A9993E364706816ABA3E25717850C26C9CD0D89D

Chris Saxon
November 30, 2016 - 2:08 pm UTC

Thanks for sharing.

Samby, November 30, 2016 - 2:47 pm UTC

Hi

Yes I tried for other columns hashes.iys matching.
Issue is for blob/clob columns.


Hash values are different for these columns.
Please suggest if there is any workaround.
Connor McDonald
December 01, 2016 - 12:52 am UTC

It may well the case that the storage mechanisms are different between the two platforms, and hence raw comparison fails.

You might need to extract piecewise subset of the blob/clob and then compare those.

Another point...

J. Laurindo Chiappa, November 30, 2016 - 6:16 pm UTC

My suggestion is to try a binary dump for the LOB column in both databases - maybe in one database you have some control characters (such as cr/lf combinations) not present in the other : this could explain the different hash results in the differnt dbs using the same hash algorithm....

Regards,

José Laurindo Chiappa

More to Explore

CLOB/BLOB/etc

Complete documentation on Securefiles and Large Objects here