Oracle PL/SQL - Comparing Nested Tables for Equality and Inequality

Introduction

If two nested table variables have the same nested table type, and that nested table type does not have elements of a record type.

Then you can compare the two variables for equality or inequality with the relational operators equal (=) and not equal (<>, !=, ~=, ^=).

Two nested table variables are equal if and only if they have the same set of elements (in any order).

The following code compares nested table variables for equality and inequality.

Demo

SQL>
SQL> DECLARE-- from   w ww  .j  av  a 2 s  .c om
  2    TYPE StringTable IS TABLE OF VARCHAR2(30); -- element type is not record type
  3
  4    dept_names1 StringTable := StringTable('A','B','C','D');
  5
  6    dept_names2 StringTable := StringTable('A','B','C','D');
  7
  8    dept_names3 StringTable := StringTable('A','B','C');
  9
 10  BEGIN
 11    IF dept_names1 = dept_names2 THEN
 12      DBMS_OUTPUT.PUT_LINE('dept_names1 = dept_names2');
 13    END IF;
 14
 15    IF dept_names2 != dept_names3 THEN
 16      DBMS_OUTPUT.PUT_LINE('dept_names2 != dept_names3');
 17    END IF;
 18  END;
 19  /
dept_names1 = dept_names2
dept_names2 != dept_names3

PL/SQL procedure successfully completed.

SQL>

Related Topic