COMPARE v17

The COMPARE procedure performs an exact byte-by-byte comparison of two large objects for a given length at given offsets. The large objects being compared must be the same data type. BFILEs must already be open when using this procedure for comparisons.

<status> NUMBER COMPARE(<lob_1> { BLOB | CLOB },
   <lob_2> { BLOB | CLOB }
   [, <amount> NUMBER [, <offset_1> NUMBER [, <offset_2> NUMBER ]]])

<status> NUMBER COMPARE(<lob_1> { BFILE}, <lob_2> { BFILE }
   [, <amount> NUMBER [, <offset_1> NUMBER [, <offset_2> NUMBER ]]])

Parameters

lob_1

Large object locator of the first large object to compare. Must be the same data type as lob_2.

lob_2

Large object locator of the second large object to compare. Must be the same data type as lob_1.

amount

If the data type of the large objects is BLOB or BFILE, then the comparison is made for amount bytes. If the data type of the large objects is CLOB, then the comparison is made for amount characters. The default is the maximum size of a large object.

offset_1

Position in the first large object to begin the comparison. The first byte/character is offset 1. The default is 1.

offset_2

Position in the second large object to begin the comparison. The first byte/character is offset 1. The default is 1.

status

Zero if both large objects are exactly the same for the specified length for the specified offsets. Nonzero if the objects aren't the same. NULL if amount, offset_1, or offset_2 are less than zero.

Example

DECLARE
   /* Initialize the BFILE locator: */
   File_loc1       BFILE := BFILENAME('ANOTHER_DIR', 'a.txt');
   File_loc2       BFILE := BFILENAME('ANOTHER_DIR', 'b.txt');
   Retval          NUMBER;
BEGIN
   DBMS_LOB.OPEN(File_loc1, DBMS_LOB.LOB_READONLY);
   DBMS_LOB.OPEN(File_loc2, DBMS_LOB.LOB_READONLY);
   Retval := DBMS_LOB.COMPARE(File_loc2, File_loc1, DBMS_LOB.LOBMAXSIZE, 1, 1);
   DBMS_OUTPUT.PUT_LINE('BFILE comparison result :' || Retval);
   /* Close the BFILEs: */
   DBMS_LOB.CLOSE(File_loc1);
   DBMS_LOB.CLOSE(File_loc2);
END;