【发布时间】:2010-02-05 15:20:38
【问题描述】:
谁能解释一下 Oracle 中的嵌套表对象是什么?在构建系统之间的接口时,我发现对我来说是一个奇怪的列 SYS_NC00054$。经过一番研究,我发现它是我创建的基于函数的索引中的嵌套表对象。
【问题讨论】:
标签: oracle nested-table
谁能解释一下 Oracle 中的嵌套表对象是什么?在构建系统之间的接口时,我发现对我来说是一个奇怪的列 SYS_NC00054$。经过一番研究,我发现它是我创建的基于函数的索引中的嵌套表对象。
【问题讨论】:
标签: oracle nested-table
基于函数的索引不同于嵌套表。
针对实际列构建常规索引...
create index emp_job_idx on emp (job)
/
... 而基于函数的索引是建立在应用于列的函数之上的。例如,当我们查询没有时间元素的日期列时,我们可以使用什么索引......
create index emp_hire_idx on emp(trunc(hiredate))
/
当我们查询 USER_IND_COLUMNS 时,索引列在第一种情况下显示,但在第二种情况下不显示,因为我们没有索引实际列。我们看到的是系统生成的“列”....
SQL> select index_name, column_name
2 from user_ind_columns
3 where table_name = 'EMP'
4 /
INDEX_NAME COLUMN_NAME
------------------------------ ---------------
PK_EMP EMPNO
EMP_UK ENAME
EMP_JOB_IDX JOB
EMP_HIRE_IDX SYS_NC00010$
SQL>
我们可以在 USER_IND_EXPRESSIONS 中看到索引的构成 ...
SQL> select index_name, column_expression
2 from user_ind_expressions
3 where table_name = 'EMP'
4 /
INDEX_NAME COLUMN_EXPRESSION
------------------------------ --------------------
EMP_HIRE_IDC TRUNC("HIREDATE")
SQL>
嵌套表
嵌套表有所不同:它们是用户定义的简单或复杂类型的数组。它们可用于在 ORDBMS 表中定义 PL/SQL 集合或列。像这样……
SQL> create or replace type address_t
2 as object
3 (
4 address_line_1 varchar2(70)
5 , address_line_2 varchar2(70)
6 , address_line_3 varchar2(70)
7 , address_line_4 varchar2(70)
8 , address_line_5 varchar2(70)
9 , postcode postcodestructure
10 ) final;
11 /
create or replace type address_t
*
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependents
SQL>
SQL> create or replace type address_nt as table of address_t
2 /
Type created.
SQL>
SQL> create table contact_details (
2 person_id number not null
3 , email_address varchar2(254)
4 , addresses address_nt
5 )
6 nested table addresses store as nested_addresses
7 /
Table created.
SQL>
【讨论】:
基本上,一个表有一个以另一个表(或其他复杂类型)的形式存储数据的列:一个嵌套在另一个表中的表。
【讨论】: