[英]Need some assistance with LISTAGG options
LISTAGG
has a 4000 character limitation. LISTAGG
有 4000 个字符的限制。 Can anyone help with this nightmarish query?任何人都可以帮助解决这个噩梦般的查询吗?
Hi, I have this bad code in a query which feeds an application.嗨,我在为应用程序提供数据的查询中有这个错误的代码。 In this form, the query has no real criteria.
在这种形式中,查询没有真正的条件。 And because of that,
LISTAGG
is hitting the 4000 character limit.正因为如此,
LISTAGG
达到了 4000 个字符的限制。
Is there any other option here?这里还有其他选择吗? Based on how everything is concatenated, I am not seeing a simple answer:
根据所有内容的连接方式,我没有看到一个简单的答案:
SELECT
email,
first_name,
last_name,
LISTAGG(
type_id
||','|| type_status
||','|| filename
||','|| status_id
||','|| status_message
||','|| TO_CHAR(upload_date,'MM/DDYYYY')
||','|| broker
||','|| quarter
||','|| quarter_year
||':'
) WITHIN GROUP (ORDER BY upload_date DESC) filenames
FROM
(
SELECT
b.surrogate_key,
b.email,
b.type_id,
DECODE(a.file_type,NULL,0,1) type_status,
a.quarter,
a.quarter_year,
a.broker,
a.upload_date,
a.filename,
a.status_id,
b.first_name,
b.last_name,
a.status_message
FROM
(
SELECT DISTINCT
(editor || '~' || file_type) surrogate_key,
file_type,
quarter,
quarter_year,
broker,
filename,
upload_date,
status_id,
status_message
FROM upload_history
ORDER BY upload_date DESC
) a,
(
SELECT DISTINCT
(email||'~'||type_id) surrogate_key,
email,
type_id,
first_name,
last_name
FROM issuers
CROSS JOIN file_types
) b
WHERE
b.surrogate_key = a.surrogate_key(+)
)
GROUP BY
email,
first_name,
last_name,
type_id,
quarter,
quarter_year;
The classical workaround the 4000 chars limitation of LISTAGG
is to use XMLAGG
, as explained in this famous AskTom post . LISTAGG
的 4000 个字符限制的经典解决方法是使用XMLAGG
,如这篇著名的 AskTom 帖子中所述。
The syntax is a bit convoluted.语法有点复杂。 In your use case, you would need to replace this :
在您的用例中,您需要替换这个:
LISTAGG(
type_id
||','|| type_status
||','|| filename
||','|| status_id
||','|| status_message
||','|| TO_CHAR(upload_date,'MM/DDYYYY')
||','|| broker
||','|| quarter
||','|| quarter_year
||':'
) WITHIN GROUP (ORDER BY upload_date DESC) filenames
With :和 :
REPLACE(REPLACE(
XMLAGG(XMLELEMENT("a",
type_id
||','|| type_status
||','|| filename
||','|| status_id
||','|| status_message
||','|| TO_CHAR(upload_date,'MM/DDYYYY')
||','|| broker
||','|| quarter
||','|| quarter_year
||':'
) ORDER BY upload_date DESC).getClobVal(),
'<a>', ''), '</a>', ',') filenames
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.