Oracle 中分隔符的模拟是什么?
What analog for separator in 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 数据库查询的模拟是什么?
更新:使用脚本时
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()
需要排序。我猜有一个列具有该名称,但可以使用任何列。
我有一个 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 数据库查询的模拟是什么?
更新:使用脚本时
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()
需要排序。我猜有一个列具有该名称,但可以使用任何列。