Oracle PL/SQL - Data Type Compatibility

Introduction

You can assign a collection to a collection variable only if they have the same data type.

In the following code, VARRAY types StringList and MyList have the same element type, VARCHAR(15).

Collection variables group1 and group2 have the same data type, StringList, but collection variable group3 has the data type MyList.

The assignment of group1 to group2 succeeds, but the assignment of group1 to group3 fails.

Demo

SQL>
SQL> DECLARE-- ww w  . j a  v  a 2 s .  c o m
  2    TYPE StringList IS VARRAY(3) OF VARCHAR2(15);
  3    TYPE MyList     IS VARRAY(3) OF VARCHAR2(15);
  4
  5    group1 StringList := StringList('A', 'B', 'C');
  6    group2 StringList;
  7    group3 MyList;
  8  BEGIN
  9    group2 := group1;  -- succeeds
 10    group3 := group1;  -- fails
 11  END;
 12  /
  group3 := group1;  -- fails
            *
ERROR at line 10:
ORA-06550: line 10, column 13:
PLS-00382: expression is of wrong type
ORA-06550: line 10, column 3:
PL/SQL: Statement ignored


SQL>

Related Topic