我有一个类似下面的查询,并列出了它的输出:
SELECT DISTINCT TRACKING_NUM,TITLE_OF_DOC_SEC FROM some_table WHERE TRACKING_NUM IS NOT NULL;
o / p:
TRACKING_NUM TITLE_OF_DOC_SEC 007 Email Flow 007 Test Bug 53306 007 Title 1119 007 Title Test 007 test bug 009 1156 089 Title 21173 098 test Doc Section
我想重新编写查询,以便获得如下输出:
TRACKING_NUM TITLE_OF_DOC_SEC 007 Email Flow,Test Bug 53306,Title 1119,Title Test,test bug 009 1156 089 Title 21173 098 test Doc Section
有人可以帮忙吗?
在11g中使用Listagg()或在10g中使用WM_Concat():
SELECT LISTAGG(TITLE_OF_DOC_SEC, ',') WITHIN GROUP (ORDER BY TRACKING_NUM) AS TITLE_OF_DOC_SEC FROM your table WHERE.... SELECT WM_CONCAT(TITLE_OF_DOC_SEC) AS TITLE_OF_DOC_SEC FROM your table WHERE....