Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles
New Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 







Compare two CLOB columns with dbms_lob

Oracle Database Tips by Donald BurlesonDecember 26, 2015

Question:  I need to compare the contents of two CLOB datatypes in a column.  How do you compare CLOB columns?  How I can compare CLOB column in two table?

Answer: Oracle provides the dbms_lob package, specifically the procedure for comparing two CLOBs. The procedure returns a zero of the strings match and a -1 if they do not match. 

Example using in SQL

In this example, we use in SQL to compare if two CLOB columns are matching in two separate tables:
  For using in SQL, you can compare two LOB columns within a single table, joining the table against itself, like this example comparing the CLOB column col1 with CLOB column col2. 

   tab1   a,
   tab1   b
   a.tab_key = b.tab_key;

In this example, we might use a cross join to display rows where the CLOB column are duplicates.

BEWARE:  This code below is a cross join because there is no table join criteria in the where clause.  This produces a Cartesian product of all rows in the table, so don't; expect sub-second response time:

   customer   a,
   customer   b
(a.clob_comments, b.clob_comments) = 0;

Now let's look at examples of using to compare two CLOB columns in PL/SQL.

Example using in PL/SQL

Here is a simple example of using to compare two CLOB datatypes in PL/SQL:

   c1 clob := 'don';
   c2 clob := 'burleson';
      dbms_output.put_line( c1, c2 ) );

In this example, would return -1 because the two CLOB values do not match.

We can also use with SQL inside PL/SQL, something like this:

   c1 clob := 'don';
   c2 clob := 'burleson';
      dbms_output.put_line( c1, c2 ) );

You can also use to compare substrings within a CLOB.  In this example, we add three arguments after the c1 and c2 arguments:

  • argument 1 - This is the first CLOB

  • argument 2 - This is the second CLOB

  • argument 3- This is the number of bytes to compare

  • argument 4 - this is the offset into string1 (c1)

  • argument 5 - This is the offset into string2 (c1)

Consider this example and note the area of matching text:

    c1 clob := 'don';
   c2 clob := 'mastadon';
      dbms_output.put_line( c1, c2, 3, 1, 6 ) );

Above we return a zero(0) value because we are matching three letters, the first three in string c1 (don) with the three letters in string 3, starting at position 5 (don).

If you like Oracle tuning, you may enjoy my new book "Oracle Tuning: The Definitive Reference", over 900 pages of BC's favorite tuning tips & scripts. 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts.



Oracle Training at Sea
oracle dba poster

Follow us on Twitter 
Oracle performance tuning software 
Oracle Linux poster


Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright © 1996 -  2017

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

Remote Emergency Support provided by Conversational