8

How to check if there is a duplicate of a blob in a database. I have documents table in the database, however I'm not sure how to check if one of them has a duplicate. I know you're supposed to use dbms_lob.compare function but after reading a few threads and articles on the topic I still do not understand this.

Documents table has document_id column and and data(blob) column. How can I possibly check if document_id = 1 has a duplicate?

MT0
  • 143,790
  • 11
  • 59
  • 117
hellomate
  • 133
  • 1
  • 1
  • 8
  • 2
    How many rows, how much data, and how often are you needing to do this? If there's a lot, `dbms_lob.compare` will be slower the more rows there are; it might be better to compute a hash and look for duplicates on that instead. – Jeffrey Kemp Dec 08 '17 at 05:57

1 Answers1

15

See other similar answers, like this one. "If dbms_lob.compare(lob1, lob2) = 0, they are identical."

select *
from documents dup
join documents orig on orig.document_id = 1
    and dup.document_id <> orig.document_id
where dbms_lob.compare(orig.blob, dup.blob) = 0;
kfinity
  • 8,581
  • 1
  • 13
  • 20