Oracle sql select 来自 table 的数据,其中嵌套了属性 table
Oracle sql select data from table where attribute is nested table
我有一个对象:
create type t_history_rec is object
(
date_from date,
current float
);
create type t_history is table of t_history_rec;
和table定义:
create table person
(
id integer primary key,
name varchar2(30),
history t_history
);
我想得到 select 名字,history.date_from,history.current 像这样:
name1 date1 current1
name1 date2 current2
name2 date3 current3
...
如何做到这一点?
无法验证这一点,但您可以尝试这样的操作:
select p.name, pp.date_from, pp.current
from person p, table(p.history) pp;
您有一些错误。 current
已保留
create or replace type t_history_rec is object
(
date_from date,
curr float
);
/
create type t_history is table of t_history_rec;
/
Table定义需要store as
create table person
(
id integer primary key,
name varchar2(30),
history t_history
) NESTED TABLE history STORE AS col1_tab;
insert into person (id, name, history) values (1, 'aa', t_history(t_history_rec(sysdate, 1)));
insert into person (id, name, history) values (2, 'aa', t_history(t_history_rec(sysdate, 1), t_history_rec(sysdate, 1)));
那么select就是:
SELECT t1.name, t2.date_from, t2.curr FROM person t1, TABLE(t1.history) t2;
我有一个对象:
create type t_history_rec is object
(
date_from date,
current float
);
create type t_history is table of t_history_rec;
和table定义:
create table person
(
id integer primary key,
name varchar2(30),
history t_history
);
我想得到 select 名字,history.date_from,history.current 像这样:
name1 date1 current1
name1 date2 current2
name2 date3 current3
...
如何做到这一点?
无法验证这一点,但您可以尝试这样的操作:
select p.name, pp.date_from, pp.current
from person p, table(p.history) pp;
您有一些错误。 current
已保留
create or replace type t_history_rec is object
(
date_from date,
curr float
);
/
create type t_history is table of t_history_rec;
/
Table定义需要store as
create table person
(
id integer primary key,
name varchar2(30),
history t_history
) NESTED TABLE history STORE AS col1_tab;
insert into person (id, name, history) values (1, 'aa', t_history(t_history_rec(sysdate, 1)));
insert into person (id, name, history) values (2, 'aa', t_history(t_history_rec(sysdate, 1), t_history_rec(sysdate, 1)));
那么select就是:
SELECT t1.name, t2.date_from, t2.curr FROM person t1, TABLE(t1.history) t2;