2016-11-07 11 views
1

である私は、オブジェクト持ってどこOracleは、テーブルからデータを選択するSQL:属性は、ネストした表

create type t_history_rec is object 
(
    date_from date, 
    current float 
); 

create type t_history is table of t_history_rec; 

と、テーブルに定義:

create table person 
(
    id integer primary key, 
    name varchar2(30), 
    history t_history 

); 

を、私は選択の名前を取得したい、history.date_from、歴史。現在のように:

name1 date1 current1 
name1 date2 current2 
name2 date3 current3 
... 

これを行う方法?

答えて

1

あなたは多少の誤差があります。 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; 
/

表の定義がある選択し

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))); 

store asを必要とします:

SELECT t1.name, t2.date_from, t2.curr FROM person t1, TABLE(t1.history) t2; 
2

はこれを確認することはできませんが、このような何かを試みることができる:

select p.name, pp.date_from, pp.current 
from person p, table(p.history) pp; 
+1

オブジェクトが正しく作成されたときにそれが動作します。 – Kacper

関連する問題