[英]Oracle - Nested Table fetching results
嵌套表格有問題。 我不知道我是否可以按照我想要的方式獲取結果。 例如,我有:
create type Name as Object(
firstname varchar2(20),
lastname varchar2(20))final;
create type Author as Object(
authorName Name);
create type Author_list as table of Author;
create table books(bookID int primary key, author Author_list) nested table author store as Author_nested;
當我使用以下方法獲取結果時:
select b.bookID, a.authorname.firstname||' '||a.authorname.lastname
from books b, table(b.author) a;
我正在為每位作者提供特定的行。 我希望針對特定bookID的作者顯示在該行中並以逗號分隔。 那可能嗎?
例如:bookID,作者名1,ab,cd,de
是的,這是可能的(一種方法是使用LISTAGG
):
select b.bookID,
LISTAGG(a.authorname.firstname||' '||a.authorname.lastname, ',')
WITHIN GROUP(ORDER BY b.BookId) AS authorname
from books b, table(b.author) a
GROUP BY b.bookID
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.