oracle 的wm_concat 和mysql 的group_concat类似,主要是先分组,然后将分组后输入同组的的内容用","拼接在一期
例子:
SELECT a.period_id,
wm_concat( b.activity_id) ACTIVITY_ID,
wm_concat(a.lottery_number) LOTTERY_NUMBER,
wm_concat(b.period_number) PERIOD_NUMBER,
wm_concat(b.total_amount) COUNT,
wm_concat(REPLACE(MOBILE, SUBSTR(a.mobile,4,4), '****')) MOBILE,
wm_concat(TO_CHAR(b.open_time,'yyyy-mm-dd hh24:mi:ss') ) OPEN_TIME
FROM A5_PPS_SEIZE_LOTTERY a ,
a5_pps_seize_activity_period b
WHERE a.period_id=b.period_id
那为什么我还wm_concat 那么多别的字段了?因为出来要返回period_id,mobile外,其他字段也需要返回,所有虽然拼接多了很多字段,但是有些自读是一样的,比如 ACTIVITY_ID等,这些自读返回后 用“,”切割成数组取出第一个就好了。
刚开始 使用ibatis映射时老是报错
Cause: com.ibatis.common.beans.ProbeException: There is no WRITEABLE property named 'ACTIVITY_ID)' in class 'java.lang.Object'
原始简化代码如下:
SELECT *
FROM
(SELECT rownum rn,
d.*
FROM
(SELECT a.period_id,
wm_concat( b.activity_id)
FROM A5_PPS_SEIZE_LOTTERY a ,
a5_pps_seize_activity_period b
WHERE a.period_id=b.period_id
AND a.is_win =1
GROUP BY a.period_id
ORDER BY a.period_id DESC
)d
)
WHERE rn > 0
AND rn <= 10
发来发现 wm_concat( b.activity_id) 后面要取个别名,才会不报上面那个映射错误,正确写法如下
SELECT *
FROM
(SELECT rownum rn,
d.*
FROM
(SELECT a.period_id,
wm_concat( b.activity_id) activity_id
FROM A5_PPS_SEIZE_LOTTERY a ,
a5_pps_seize_activity_period b
WHERE a.period_id=b.period_id
AND a.is_win =1
GROUP BY a.period_id
ORDER BY a.period_id DESC
)d
)
WHERE rn > 0
AND rn <= 10