【问题标题】:Oracle Self-dependency type declarationOracle 自依赖类型声明
【发布时间】:2018-09-12 02:29:47
【问题描述】:

我想在 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


    【解决方案1】:

    好吧,您可以再次重复第一个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>
    

    【讨论】:

    • 嗨..如何在上面的查询中创建 items_table 而不使用“ref”。
    • 据我所知,两种对象类型中不能有相互依赖的对象。其中至少一个必须是reference
    猜你喜欢
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 2016-12-17
    • 2013-03-03
    • 1970-01-01
    相关资源
    最近更新 更多