Oracle关联数组,如何定义?
Oracle Associative arrays, how to define?
我正在尝试在 Oracle 中创建关联数组,当我创建嵌套 table 时,它工作正常:
CREATE OR REPLACE TYPE TRNG_BOOK_AUTHORS_TAB
AS TABLE OF VARCHAR2(500);
但是当我添加索引时出现错误:
CREATE OR REPLACE TYPE TRNG_BOOK_AUTHORS_TAB
AS TABLE OF VARCHAR2(500) INDEX BY PLS_INTEGER;
- 错误:PL/SQL:编译单元分析终止
- 错误(2,4):PLS-00355:在此上下文中不允许使用 pl/sql table
我哪里做错了?
您正在创建模式类型;这些可以是嵌套表或可变数组 (varrays),但不能是关联数组。
来自 the create type
statement 的文档:
A standalone collection type that you create with the CREATE TYPE
statement differs from a collection type that you define with the keyword TYPE
in a PL/SQL block or package. For information about the latter, see "Collection Variable Declaration".
With the CREATE TYPE
statement, you can create nested table and VARRAY
types, but not associative arrays. In a PL/SQL block or package, you can define all three collection types.
我正在尝试在 Oracle 中创建关联数组,当我创建嵌套 table 时,它工作正常:
CREATE OR REPLACE TYPE TRNG_BOOK_AUTHORS_TAB
AS TABLE OF VARCHAR2(500);
但是当我添加索引时出现错误:
CREATE OR REPLACE TYPE TRNG_BOOK_AUTHORS_TAB
AS TABLE OF VARCHAR2(500) INDEX BY PLS_INTEGER;
- 错误:PL/SQL:编译单元分析终止
- 错误(2,4):PLS-00355:在此上下文中不允许使用 pl/sql table
我哪里做错了?
您正在创建模式类型;这些可以是嵌套表或可变数组 (varrays),但不能是关联数组。
来自 the create type
statement 的文档:
A standalone collection type that you create with the
CREATE TYPE
statement differs from a collection type that you define with the keywordTYPE
in a PL/SQL block or package. For information about the latter, see "Collection Variable Declaration".With the
CREATE TYPE
statement, you can create nested table andVARRAY
types, but not associative arrays. In a PL/SQL block or package, you can define all three collection types.