首页 > 解决方案 > Oracle 中分隔符的类比是什么?

问题描述

我有一个 SQL 请求,在 H2 DB 中工作正常:

update task_display td
set comments = (
    select group_concat(co.text separator '\n\n')
    from comments co
             left join ticket ti on co.ticket_id = ti.id
    where td.ticket_id = ti.id
    );

如我们所见,我使用separator分隔文本。Oracle 数据库的这个查询有什么相似之处?

UPD:使用脚本时

update task_display td
    set comments = (select listagg(co.text, '\n\n') within group (order by co.id)
                    from comments co
                    where td.ticket_id = co.ticket_id
                   );

我重新收到此错误:

ORA-01489: result of string concatenation is too long
01489. 00000 -  "result of string concatenation is too long"
*Cause:    String concatenation result is more than the maximum size.
*Action:   Make sure that the result is less than the maximum size.

标签: sqloraclestring-aggregation

解决方案


假设您的字符串足够大以存储值:

update task_display td
    set comments = (select listagg(co.text, '\n\n') within group (order by co.id)
                    from comments co
                    where td.ticket_id = co.ticket_id
                   );

我认为在这两个数据库中都不join需要ticket

order by co.id是因为listagg()需要订购。我猜有一个具有该名称的列,但可以使用任何列。


推荐阅读