Listagg溢出函数实现(Oracle SQL)

时间:2018-02-12 15:40:46

标签: sql oracle

我在查询中使用LISTAGG函数,但是它返回了ORA-01489: result of string concatenation is too long错误。所以我用Google搜索了这个错误,发现我可以使用ON OVERFLOW TRUNCATE并将其实现到我的SQL中,但现在它会生成missing right parenthesis错误,而我似乎无法找出原因?

我的查询

SELECT DISTINCT cust_id, acct_no, state, language_indicator, billing_system, market_code,
EMAIL_ADDR, DATE_OF_CHANGE, TO_CHAR(DATE_LOADED, 'DD-MM-YYYY') DATE_LOADED, 
(SELECT LISTAGG( SUBSTR(mtn, 7, 4),'<br>' ON OVERFLOW TRUNCATE '***' )
WITHIN GROUP (ORDER BY cust_id || acct_no) mtnlist
FROM process.feature WHERE date_loaded BETWEEN TO_DATE('02-08-2018','MM-dd-yyyy')
AND TO_DATE('02-09-2018', 'MM-dd-yyyy') AND cust_id = ffsr.cust_id
AND acct_no = ffsr.acct_no AND filename = 'FEATURE.VB2B.201802090040'
GROUP BY cust_id||acct_no) mtnlist
FROM process.feature ffsr WHERE date_loaded BETWEEN TO_DATE('02-08-2018','MM-dd-yyyy')
AND TO_DATE('02-09-2018','MM-dd-yyyy') AND cust_id BETWEEN 0542185146 AND 0942025571
AND src_ind = 'B' AND filename = 'FEATURE.VB2B.201802090040'
AND letter_type = 'FA' ORDER BY cust_id;

2 个答案:

答案 0 :(得分:3)

通过XML的一些帮助,您可能会得到它的工作。示例基于HR模式。

\x00

答案 1 :(得分:2)

此演示源自livesql.oracle.com

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe