oracle 合并函数wm_concat(column)和分割函数


wm_concat(column)

-----------------------------------------
u_id       goods            num
------------------------------------------
1                苹果                2
2                 梨子               5
1                 西瓜               4
3                 葡萄               1
3                香蕉                1
1               橘子                 3
=======================
想要的结果为:
--------------------------------
u_id          goods_sum
____________________
1              苹果,西瓜,橘子
2              梨子
3              葡萄,香蕉
---------------------------------
1.select u_id, wmsys.wm_concat(goods) goods_sum  2. 3.from shopping  4. 5.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 

mysql---group_concat




oracle分割可以用一下这种方法:

SELECT
  SUBSTR( 'repconf:234,242424,3334' ,
               INSTR( 'repconf:234,242424,3334' ',' ) + 1,
               INSTR( 'repconf:234,242424,3334' ,
                     ',' ,
                     INSTR( 'repconf:234,242424,3334' ',' ) + 1) -
               (INSTR( 'repconf:234,242424,3334' ',' ) + 1))
   FROM  DUAL;

还可以参考
http://blog.csdn.net/q1059081877q/article/details/46885339

你可能感兴趣的:(数据库,oracle,数据库oracle)