美好的一天。我正在编写一个使用 LISTAGG 并返回结果的查询。这是我到目前为止的代码。
select
listagg(rtrim(shop_cde, 1), ', ') within group (order by shop_cde) col1,
business_cde
from mytable
group by business_cde
我希望这会返回结果,聚合它们,并从 shop_cde 的右侧修剪掉 1 个字符。然而,似乎没有发生修剪。 Shop_cde 仍然完整显示。有谁知道如何在 LISTAGG 函数中 TRIM ?
最佳答案
trim()
函数通常用于删除前导空格和尾随空格(尽管您也可以删除其他字符)。
如果您想丢弃最后一个字符,请使用substr()
:
select listagg(substr(shop_cde, 1, length(shop_cde) - 1), ', ') within group (order by shop_cde) col1,
business_cde
from mytable
group by business_cde
关于sql - LISTAGG 内的 RTRIM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57116806/