我正在尝试执行以下操作:
1) 创建或替换类型交易作为对象(日期日期,描述 varchar(30));
创建或替换类型T_transaction作为交易表;
2) 创建或替换类型 account 作为对象 (id int, description varchar(30),
t_交易 T_交易)
嵌套表 t_transaction 存储为 xxx1;
创建或替换类型 T_account 作为科目表;
3) 创建或替换类型 user 作为对象 (id int, descr varchar(30), t_account T_帐户) 嵌套表 t_account 存储为 xxx2;
创建或替换类型T_user作为用户表;
4) 创建或替换表库(名称 varchar(20),用户 T_user) 嵌套表用户存储为xxx3;
前 2 个类型已成功创建,但“创建或替换类型帐户...”给出 -> 警告:创建的类型有编译错误。
是否有使用多层嵌套表创建此类数据库的建议?
最佳答案
编辑:
我对这个主题(对象嵌套限制)做了一些研究,以下是我的发现:
根据Database Limits ,
嵌套表的每一列实际上都会添加到主机表的列中,表中的最大总列数为 1000。
因此,这将是官方上限(如果每个嵌套表都有一个列)。
但是,当我进行实际测试时(在11g和12c上),由于错误,我无法创建嵌套深度超过50的表
ORA-00036:超出递归 SQL 级别的最大数量 (50)
。
因此我得出结论,最大可能的嵌套深度是 50。
初始答案:
我不知道对象嵌套的限制,但我认为它们应该是相当宽松的。
您的代码失败是因为您犯了一些错误:
1. 使用类型名称作为列名称(date
、t_account
等);
2. 在错误的地方使用nested table
子句;
代码应该是这样的:
create or replace type transaction_type as object (tx_date Date, description varchar2(30));
create or replace type transaction_tab as table of transaction_type;
create or replace type account_type as object (id int, description varchar(30),
transactions transaction_tab);
create or replace type account_tab as table of account_type;
create or replace type user_type as object (id int, descr varchar(30), accounts account_tab);
create or replace type user_tab as table of user_type;
CREATE table banks (name varchar(20), users user_tab)
nested table users store as xxx3 (
nested table accounts store as xxx2 (
nested table transactions store as xxx1
));
检查
INSERT INTO banks VALUES (
'John', user_tab(
user_type(1
,'regular user'
, account_tab(
account_type(1
,'regular account'
, transaction_tab(transaction_type(
trunc(sysdate)
, 'regular transaction'))
))
)));
SQL> SELECT *FROM banks;
NAME
--------------------
USERS(ID, DESCR, ACCOUNTS(ID, DESCRIPTION, TRANSACTIONS(TX_DATE, DESCRIPTION)))
--------------------------------------------------------------------------------
John
USER_TAB(USER_TYPE(1, 'regular user', ACCOUNT_TAB(ACCOUNT_TYPE(1, 'regular accou
nt', TRANSACTION_TAB(TRANSACTION_TYPE('04-APR-18', 'regular transaction'))))))
选择嵌套表格列
SELECT b.name, u.id, u.descr, a.id, a.description
FROM banks b, table(b.users) u, table(u.accounts) a
WHERE u.descr = 'regular user' AND a.description = 'regular account'
NAME ID DESCR ID DESCRIPTION
----- --- ------------- --- ----------------
John 1 regular user 1 regular account
关于oracle12c - Oracle 12c 中的嵌套表级别可以有多深?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49636661/