PL/SQL:使用 id 嵌套 table 并创建视图
PL/SQL: nested table with id's and create view
我已经创建了 tables,通过其中之一的嵌套 table 链接:
CREATE TABLE A (
NAME VARCHAR(150) ,
ID INTEGER PRIMARY KEY
) ;
CREATE TYPE A_LIST IS TABLE OF integer;
CREATE TABLE B (
NAME VARCHAR(150),
ID INTEGER PRIMARY KEY,
LIST A_LIST
) NESTED TABLE LIST STORE AS LIST_TABLE;
现在我需要创建视图来显示来自 table B 的数据和来自 A 的嵌套数据。它类似于
CREATE OR REPLACE VIEW ff OF B, A AS
SELECT N.name, N.LIST
CAST( MULTISET (
....
)AS TYPE_FILM_LIST)
FROM B N;
但我被困在那些点中(
如果您想根据嵌套 ID 加入 tables B 和 A - 这里是一个例子。
一些测试数据
insert into b
values ('x',1, A_LIST(1,2,3));
insert into a values ('A1',1);
insert into a values ('A2',2);
insert into a values ('A3',3);
主要步骤是 table B 与嵌套 table from b, table(b.list)
的连接,嵌套 ID 返回为 COLUMN_VALUE
;剩下的很简单加入
select b.id, b.name, a.name a_name, a.id a_id from b, table(b.list) ba, a
where ba.column_value = a.id;
结果
ID SUBSTR(B.NAME,1,5) A_NAME A_ID
---------- ------------------ ------ ----------
1 x A1 1
1 x A2 2
1 x A3 3
create type record_for_a is object( a varchar2(150), id number);
create type l_record_for_a is table of record_for_a;
select table_b.name, table_b.id,
cast( multiset (select record_for_a(aa.name,aa.id) from a aa, table(table_b.list) bb where aa.id = bb.column_value) as l_record_for_a)
neste_col_a
from
b table_b;
我已经创建了 tables,通过其中之一的嵌套 table 链接:
CREATE TABLE A (
NAME VARCHAR(150) ,
ID INTEGER PRIMARY KEY
) ;
CREATE TYPE A_LIST IS TABLE OF integer;
CREATE TABLE B (
NAME VARCHAR(150),
ID INTEGER PRIMARY KEY,
LIST A_LIST
) NESTED TABLE LIST STORE AS LIST_TABLE;
现在我需要创建视图来显示来自 table B 的数据和来自 A 的嵌套数据。它类似于
CREATE OR REPLACE VIEW ff OF B, A AS
SELECT N.name, N.LIST
CAST( MULTISET (
....
)AS TYPE_FILM_LIST)
FROM B N;
但我被困在那些点中(
如果您想根据嵌套 ID 加入 tables B 和 A - 这里是一个例子。
一些测试数据
insert into b
values ('x',1, A_LIST(1,2,3));
insert into a values ('A1',1);
insert into a values ('A2',2);
insert into a values ('A3',3);
主要步骤是 table B 与嵌套 table from b, table(b.list)
的连接,嵌套 ID 返回为 COLUMN_VALUE
;剩下的很简单加入
select b.id, b.name, a.name a_name, a.id a_id from b, table(b.list) ba, a
where ba.column_value = a.id;
结果
ID SUBSTR(B.NAME,1,5) A_NAME A_ID
---------- ------------------ ------ ----------
1 x A1 1
1 x A2 2
1 x A3 3
create type record_for_a is object( a varchar2(150), id number);
create type l_record_for_a is table of record_for_a;
select table_b.name, table_b.id,
cast( multiset (select record_for_a(aa.name,aa.id) from a aa, table(table_b.list) bb where aa.id = bb.column_value) as l_record_for_a)
neste_col_a
from
b table_b;