sql - 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.
解决方案
假设您的字符串足够大以存储值:
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()
需要订购。我猜有一个具有该名称的列,但可以使用任何列。
推荐阅读
- raku - 并发,一次对多个供应做出反应
- android - 清单合并失败并出现多个错误无法确定问题
- c# - 如何修复“对于 UInt32 而言,值太大或太小”C#
- javascript - 为什么 NextJS 中未定义查询参数?
- spring - 自动装配时会返回实例的副本吗?
- javascript - 通过更新谷歌表格中的行在谷歌驱动器中创建文件夹
- c++ - 优化写入内存
- delphi - Delphi 10.3.2 Build 找不到 DFM 文件
- prolog - 在 swi-prolog 中;如何创建 dup(L1, L2),其中 L2 的元素是 L1 的重复元素?
- python - 如何在 Python 中获得 Kruskal Wallis 测试的效果大小?