是否可以在 listagg 函数中没有 order by 子句?我应该这样做以保留值的顺序。顺便说一句,我正在使用 oracle 11g。以下是我正在使用的查询:
SELECT
wipData."Transaction Type"
,wipData."Details"
,wipData."Values"
,NULL
,wipdata.containerid
,wipdata.specid
,wipdata.wiptrackinggroupkeyid
,wipdata.wiplothistoryid
,NULL wipdatasetupid
,wipdata.specname
,NULL linkid
FROM
(
SELECT wipdata.containerid
,wipdata.wiplothistoryid
,wipdata.wiptrackinggroupkeyid
,wipdata.specid
,wipdata.specname
,'WIP Data Collection @'|| SUBSTR(wipdata.specname,0,4) AS "Transaction Type"
,LISTAGG(wipdata.wipdatanamename ||': ' , 'break') WITHIN GROUP ( ORDER BY wipdata.wipdatanamename) AS "Details"
,LISTAGG(wipdata.wipdatavalue, 'break') WITHIN GROUP ( ORDER BY wipdata.wipdatanamename) AS "Values"
FROM
(
SELECT c.containerid
,wldd.wipdatanamename
,wldd.wipdatavalue
,wldd.iswaferdata
,wl.specname
,wl.wiplothistoryid
,wl.wiptrackinggroupkeyid
,wl.specid
FROM Container C
JOIN a_wiplothistory wl ON c.containerid = wl.containerid
JOIN a_wiplotdetailshistory wld ON wl.wiplothistoryid = wld.wiplothistoryid
JOIN a_wiplotdetailsdatahistory wldd ON wld.wiplotdetailshistoryid = wldd.wiplotdetailshistoryid
WHERE c.containername = :lotID AND wldd.iswaferdata = 0 AND wldd.servicename <> 'AdHocWIPData'
) wipdata
GROUP BY wipdata.containerid
,wipdata.wiplothistoryid
,wipdata.wiptrackinggroupkeyid
,wipdata.specid
,wipdata.specname
) WipData
UNION ALL
SELECT
wipData."Transaction Type"
,wipData."Details"
,wipData."Values"
,NULL
,wipdata.containerid
,wipdata.specid
,wipdata.wiptrackinggroupkeyid
,wipdata.wiplotid
,NULL
,wipdata.specname
,NULL
FROM
(
SELECT wipdata.containerid
,wipdata.wiplotid
,wipdata.wiptrackinggroupkeyid
,wipdata.specid
,wipdata.specname
,'WIP Data Collection @'|| SUBSTR(wipdata.specname,0,4) AS "Transaction Type"
,LISTAGG(wipdata.wipdatanamename ||': ' || wipdata.wipdatavalue, 'break') WITHIN GROUP ( ORDER BY wipdata.wipdatanamename) AS "Details"
,LISTAGG(wipdata.wipdatavalue, 'break') WITHIN GROUP ( ORDER BY wipdata.wipdatanamename) AS "Values"
FROM
(
SELECT c.containerid
,wldd.wipdatanamename
,wldd.wipdatavalue
,wldd.iswaferdata
,wl.specname
,wl.wiplotid
,wl.wiptrackinggroupkeyid
,wl.specid
FROM Container C
JOIN a_wiplot wl ON c.containerid = wl.containerid
JOIN a_wiplotdetails wld ON wl.wiplotid = wld.wiplotid
JOIN a_wiplotdetailsdata wldd ON wld.wiplotdetailsid = wldd.wiplotdetailsid
WHERE c.containername = :lotID AND wldd.iswaferdata = 0 AND wldd.servicename <> 'AdHocWIPData'
) wipdata
GROUP BY wipdata.containerid
,wipdata.wiplotid
,wipdata.wiptrackinggroupkeyid
,wipdata.specid
,wipdata.specname
) WipData
谢谢你们。