我有一个像下面的查询和列出的输出:
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....