我已经被困了一段时间了。 我正在尝试检索VARRAY中的值并将其查询到另一个值下的同一行,在本例中为游戏的标题,请参阅下面的详细信息。这些表目前是这样的(我已经采取了很多属性来简化它)
CREATE TYPE Publisher_Type AS OBJECT
(PublisherName VARCHAR2(30))
/
CREATE TABLE Publisher_Table of Publisher_Type
/
INSERT INTO Publisher_Table
VALUES ('EA')
/
CREATE OR REPLACE TYPE Genre_Game AS OBJECT
(Genre VARCHAR(20))
/
CREATE OR REPLACE TYPE Genre_Type AS VARRAY(3) OF Genre_Game
/
CREATE OR REPLACE TYPE Game_Type AS OBJECT
(Title VARCHAR2(50),
GamePublisher REF Publisher_Type
GameGenre Genre_Type)
/
CREATE Game_Table of Game_Type
/
INSERT INTO Game_Table
VALUES('Madden 17', (SELECT REF(c) FROM Publisher_Table WHERE
c.PublisherName = 'EA'), (Genre_Type(Genre_Game('Sports'),
Genre_Game('Simulation'), Genre_Game('Football')))
以下是我在线阅读一些帖子时所尝试的内容,但它不会起作用。我理想的输出是 Madden 17 EA体育,模拟,足球
SELECT title , m.GamePublisher.PublisherName,
max( decode( rn, 1, GameGenre ) ) genre1,
max( decode( rn, 2, GameGenre ) ) genre2,
max( decode( rn, 3, GameGenre ) ) genre3
FROM (
SELECT title, m.GamePublisher.PublisherName, f.*,
row_number() over (partition by title order by GameGenre) rn
FROM Game_Table m, table(m.GameGenre) f
WHERE title = 'Madden 17'
)
group by title
答案 0 :(得分:0)
您需要使用LISTAGG()来连接主题值,按游戏级别列分组。我正在使用this apparently related question I answered yesterday中的数据。
SQL> select title
2 , listagg(gt.theme, ',') within group (order by gt.theme) as themes
3 from game_table
4 , table(gametheme) gt
5 group by title;
TITLE THEMES
-------------------- -------------------------
Commander Cody Fun,Puzzle
Star Wars Action,FPS
Uncharted 3 Action,Puzzle
SQL>