In Oracle Database 10g, is it possible to create an associative array type outside of a package or procedure? I would like to be able to do this so that I can reference this associative array type in another type. For example:
create type my_type_map is table of varchar2(10) index by varchar2(10);
create type my_other_type as object (
id number(15),
member procedure initialize(p_my_type_map my_type_map)
) not instantiable not final;
The error I get is:
SQL> create type my_type_map is table of varchar2(20) index by varchar2(10);
2 /
Warning: Type created with compilation errors.
SQL> show errors;
Errors for TYPE MY_TYPE_MAP:
LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0 PL/SQL: Compilation unit analysis terminated
1/21 PLS-00355: use of pl/sql table not allowed in this context
SQL>
Seems that Oracle considers:
index by varchar2(10)
to be PL/SQL and doens't allow it in the creation of SQL types. If Oracle really doesn't allow associative arrays to be defined outside of packages then is there a good alternative? Is it possible to create types that extend Oracle's Object inside of a package so that all types are defined in the same package?
Thanks,
Jeff
Edit: Corrected code sample, added log, added possible alternative as question.
Best Answer
The answer is no, you cannot do what you're trying to do, any more than you can create a type to add a BOOLEAN typed variable to an object. The items in an object must contain Oracle types, not PL/SQL types. A bit clunky alternative could be:
Store your associated pairs of variables in the two VARRAYs. You will have to know the largest possible size of your arrays.