oracle wm concat函式的使用

2021-08-11 05:31:51 字數 1348 閱讀 1593

wm_concat函式的左右是列轉行:

例: u_id       goods            num

------------------------------------------

1                蘋果                2

2                梨子                5

1                西瓜                4

3                葡萄                1

3                香蕉                1

1                橘子                3

********************===

想要的結果為:

--------------------------------

u_id          goods_sum

____________________

1              蘋果,西瓜,橘子

2              梨子

3              葡萄,香蕉

---------------------------------

select u_id, wmsys.wm_concat(goods) goods_sum

from shopping

group by u_id

想要的結果2:

--------------------------------

u_id          goods_sum

____________________

1              蘋果(2斤),西瓜(4斤),橘子(3斤)

2              梨子(5斤)

3              葡萄(1斤),香蕉(1斤)

---------------------------------

使用oracle wm_concat(column)函式實現:

select u_id, wmsys.wm_concat(goods || '(' || num || '斤)' ) goods_sum

from shopping

group by u_id

但是這個函式有虛擬記憶體,超過該虛擬記憶體則報錯,即欄位過長,在出現該情況時,需要把wm_concat函式轉化,變成

trim(xmlagg(xmlelement(content, (需要列變行的字段) || ',' ) order by (需要列變行的字段) ).extract('//text()').getclobval())

Oracle wm concat()函式 及排序

今天在專案中修改了乙個sql select t.dmid bmid,wm concat m.xm fgld from gg user m,gg dmnr qx t where m.id t.czyid group by dmid 這個函式也夠把符合條件的幾條資料的某一列 合併成一條資料中的某一列 比...

oracle wm concat函式的使用

oracle wm concat column 函式使我們經常會使用到的,下面就教您如何使用oracle wm concat column 函式實現字段合併,如果您對oracle wm concat column 函式使用方面感興趣的話,不妨一看。shopping u id goods num 1 ...

Oracle wm concat函式排序的解決方法

預設情況下,使用wm concat和group by拼接欄位時,拼接的字段順序是無規則的。建立測試資料 create table tb seq number 10 remark varchar2 100 createtime date insert into tb seq,remark,create...