Oracle PL/SQL Tutorial/Collections/IS EMPTY

Материал из SQL эксперт
Перейти к: навигация, поиск

IS EMPTY Operator

You use the IS EMPTY operator to check if a nested table doesn"t contain elements. The following procedure, is_empty_example(), illustrates the use of IS EMPTY:



SQL>
SQL> CREATE OR REPLACE PROCEDURE is_empty_example AS
  2    TYPE nestedTableType IS TABLE OF VARCHAR2(10);
  3    myTable1 nestedTableType;
  4    result BOOLEAN;
  5  BEGIN
  6    myTable1 := nestedTableType("F", "G", "S");
  7    result := myTable1 IS EMPTY;
  8    IF result THEN
  9      DBMS_OUTPUT.PUT_LINE("Nested table is empty");
 10    ELSE
 11      DBMS_OUTPUT.PUT_LINE("Nested table contains elements");
 12    END IF;
 13  END is_empty_example;
 14  /
Procedure created.
SQL> CALL is_empty_example();
Nested table contains elements
Call completed.
SQL>
SQL>


IS EMPTY operator checks whether a VARRAY or NESTED TABLE collection variable is empty

SQL>
SQL>  DECLARE
  2     TYPE list IS TABLE OF INTEGER;
  3     a LIST := list();
  4   BEGIN
  5     IF a IS EMPTY THEN
  6       dbms_output.put_line(""a" is empty.");
  7     END IF;
  8   END;
  9   /
"a" is empty.
PL/SQL procedure successfully completed.
SQL>