[英]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.