如何使用对象类型的嵌套表创建 Oracle 表?

How do I create an Oracle table with nested tables of object types?(如何使用对象类型的嵌套表创建 Oracle 表?)
本文介绍了如何使用对象类型的嵌套表创建 Oracle 表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个高度嵌套的 OBJECT TYPE 结构,它允许我以树状方式保存数据.

I have a highly nested OBJECT TYPE structure that allows me to hold data in a tree-like manner.

我现在想创建一个表来缓存这些对象,但是我在创建表时遇到了困难.我怀疑我的问题是多个嵌套级别,但不知道如何解决.

I'd now like to create a table to cache these objects, but I'm having difficulty getting the table to create. I suspect my problem is the multiple nesting levels, but not sure how to fix.

CREATE TYPE STEP_OBJ AS OBJECT (
  ID                        VARCHAR2(20),
  OTHER_FIELDS              VARCHAR2(100));
/

CREATE TYPE STEP_TAB_OBJ AS TABLE OF STEP_OBJ;
/

CREATE TYPE TREE_OBJ AS OBJECT (
  STEPS       STEP_TAB_OBJ,
  COMPLETE    VARCHAR2(1));
/

CREATE TYPE TABLE_OF_TREE_OBJ AS TABLE OF TREE_OBJ;
/

CREATE TABLE TREE_TABLE_CACHE (
   HANDLE               VARCHAR2(20),
   TABLE_OF_TREES       TABLE_OF_TREE_OBJ)
   NESTED TABLE TABLE_OF_TREES STORE AS TREE_TABLE_CACHE_OBJS;
/

CREATE TABLE TREE_TABLE_CACHE (
*
ERROR at line 1:
ORA-02320: failure in creating storage table for nested table column TABLE_OF_TREES
ORA-22913: must specify table name for nested table column or attribute

甲骨文 11g.

推荐答案

您需要为内部集合指定一个存储子句.语法只是将嵌套集合的子句括在括号中,如下所示:

You need to specify a storage clause for the inner collection. The syntax is simply to wrap the clause for the nested collection in brackets like this:

SQL> CREATE TABLE TREE_TABLE_CACHE (
  2     HANDLE               VARCHAR2(20),
  3     TABLE_OF_TREES       TABLE_OF_TREE_OBJ)
  4     NESTED TABLE TABLE_OF_TREES STORE AS TREE_TABLE_CACHE_OBJS
  5     ( NESTED TABLE STEPS          STORE AS TREE_TABLE_CACHE_STEPS)
  8   /

Table created.

SQL> 

这篇关于如何使用对象类型的嵌套表创建 Oracle 表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)