尝试在 Oracle 中创建 table 类型时出现错误 PLS-00201

Error PLS-00201 while trying to create table type in Oracle

当我在 Oracle 19c 中 运行 这段代码时:

CREATE TYPE t_my_type IS TABLE OF my_table.my_col%TYPE;

我有这个错误:

Type t_my_type compiled

LINE/COL  ERROR
--------- -------------------------------------------------------------
0/0       PL/SQL: Compilation unit analysis terminated
1/23      PLS-00201: identifier 'my_table.my_col' must be declared
Errors: check compiler log

为什么说必须申报?

在这里找到答案:https://community.oracle.com/tech/developers/discussion/3582858/pls-00201-when-declaring-table-type

在这种情况下您不能使用 %TYPE。您必须使用一些预定义的 Oracle 类型,例如 NUMBER 或创建一个集合。

示例:

CREATE TYPE t_my_type IS TABLE OF NUMBER;