首页 > 解决方案 > Oracle 自依赖类型声明

问题描述

我想在 Oracle 中创建一个自定义类型,如下所示。任何人都可以告诉我如何实现这一点。

CREATE OR REPLACE TYPE Items_Type FORCE IS OBJECT ( "S.No" VARCHAR2(500) NULL , sub_list "Items_table" NULL  ) NOT FINAL;

CREATE OR REPLACE TYPE Items_table IS TABLE OF REF Items_Type;

标签: oracle

解决方案


好吧,您可以再次重复第CREATE OR REPLACE TYPE一次,因为第一次执行时它会失败。看一看:

SQL> -- statement A
SQL> create or replace type items_type force is object
  2    (sno      varchar2(500) null ,
  3     sub_list items_table   null
  4    ) not final;
  5  /

Warning: Type created with compilation errors.

SQL> show err
Errors for TYPE ITEMS_TYPE:

LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0      PL/SQL: Compilation unit analysis terminated
3/13     PLS-00201: identifier 'ITEMS_TABLE' must be declared
SQL>
SQL> -- statement B
SQL> create or replace type items_table is table of ref items_type;
  2  /

Type created.

SQL> -- statement A, repeated
SQL> create or replace type items_type force is object
  2    (sno      varchar2(500) null ,
  3     sub_list items_table   null
  4    ) not final;
  5  /

Type created.

SQL>

推荐阅读