簡體   English   中英

LISTAGG內的RTRIM?

[英]RTRIM inside LISTAGG?

美好的一天。 我正在編寫一個使用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

如果要從右側刪除給定數量substr ,請使用substr如果要刪除 定字符的未指定數量,請使用rtrim 刪除左側將使用substr(..., 2)ltrim ,分別。

   select 
    listagg(substr(shop_cde, -1), ', ') within group (order by shop_cde) col1,
    business_cde
    from mytable
    group by business_cde

您應該使用rtrim(listagg(....)

select 
rtrim(listagg(shop_cde, ', ') within group (order by shop_cde) ) col1,
business_cde
from mytable
group by business_cde

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM