Mega Code Archive

 
Categories / Oracle PLSQL Tutorial / Collections
 

The EXISTS Table Attribute

SQL> SQL> DECLARE   2    Type t_FirstNameTable IS TABLE OF VARCHAR(20)   3    INDEX BY BINARY_INTEGER;   4    FirstNames  t_FirstNameTable;   5  BEGIN   6    -- Insert rows into the table.   7    FirstNames(1) := 'Scott';   8    FirstNames(3) := 'Joanne';   9  10    -- Check to see if rows exist.  11    IF FirstNames.EXISTS(1) THEN  12      DBMS_OUTPUT.put_line('Row 1 exists!');  13    ELSE  14      DBMS_OUTPUT.put_line('Row 1 doesn''t exist!');  15    END IF;  16    IF FirstNames.EXISTS(2) THEN  17      DBMS_OUTPUT.put_line('Row 2 exists!');  18    ELSE  19      DBMS_OUTPUT.put_line('Row 2 doesn''t exist!');  20    END IF;  21  END;  22  / Row 1 exists! Row 2 doesn't exist! PL/SQL procedure successfully completed. SQL>