博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle(18)—— ORACLE中将查询结果的多列汇聚成一行(WMSYS.WM_CONCAT 函数的用法)...
阅读量:4331 次
发布时间:2019-06-06

本文共 2365 字,大约阅读时间需要 7 分钟。

WMSYS.WM_CONCAT 函数的用法:

引用路径:http://blog.sina.com.cn/s/blog_5c4736800100l2qw.html

 

详例sql脚本:    select b.bantchno,       c.codename,       cc.codename,       b.sendstartdate,       b.sendenddate,       b.planstartdate,       b.palnenddate,       (select wmsys.wm_concat(to_char(b1.planchildstartdate, 'yyyy-mm-dd') || '至' ||                               to_char(b1.palnchildenddate, 'yyyy-mm-dd')) condate          from bantchnosubmanage b1         where '1460001220000' = '1460001220000'           and b1.bantchno = b.bantchno),           (select p.pdate from ((select bantchno, ltrim(max(sys_connect_by_path(pName, ',')), ',') pdate from (select row_number() over(PARTITION by t1.bantchno ORDER by t1.bantchno) r,t1.*, (to_char(t2.planchildstartdate,'yyyy-MM-dd')||'至'||to_char(t2.palnchildenddate,'yyyy-MM-dd')) pName from bantchnomanage t1, bantchnosubmanage t2 where t1.bantchno = t2.bantchno order by t1.bantchno,t2.planchildstartdate )start with r=1 CONNECT by prior r =r-1 and prior bantchno = bantchno group by bantchno order by bantchno)) p where p.bantchno = b.bantchno),       b.remark  from bantchnomanage b  left join codemanage c    on c.codetype = 'MyState'   and c.codecode = b.status  left join codemanage cc    on cc.codetype = 'BooleanFlag'   and cc.codecode = b.temp1 where 1 = 1   and b.temp2 = '1' order by b.bantchno desc;

 

方案一、

select wmsys.wm_concat(to_char(b1.planchildstartdate, 'yyyy-mm-dd') || '至' ||

to_char(b1.palnchildenddate, 'yyyy-mm-dd')) condate
from bantchnosubmanage b1
where '1460001220000' = '1460001220000'
and b1.bantchno = b.bantchno

 

方案二、

select bantchno, ltrim(max(sys_connect_by_path(pName, ',')), ',') pdate

from (select row_number() over(PARTITION by t1.bantchno ORDER by t1.bantchno) r,t1.*, (to_char(t2.planchildstartdate,'yyyy-MM-dd')||'至'||to_char(t2.palnchildenddate,'yyyy-MM-dd')) pName from bantchnomanage t1, bantchnosubmanage t2 where t1.bantchno = t2.bantchno order by ....)
start with r=1 CONNECT by prior r =r-1 and prior bantchno = bantchno group by bantchno order by bantchno

方案三、

(WITH Q AS

(
SELECT bantchno key,(to_char(planchildstartdate,'yyyy-MM-dd')||'至'||to_char(palnchildenddate,'yyyy-MM-dd')) x FROM bantchnosubmanage
)

SELECT key,

RTRIM(
XMLAGG (XMLELEMENT(e, x||',') ORDER BY x).EXTRACT('//text()')
) AS concatval
FROM q 
GROUP BY key)

 

  

 

转载于:https://www.cnblogs.com/xushuyi/articles/5367423.html

你可能感兴趣的文章
学习操作系统导图
查看>>
在线的JSON formate工具
查看>>
winform非常实用的程序退出方法!!!!!(转自博客园)
查看>>
xml解析
查看>>
centos安装vim
查看>>
linux工作调度(计划任务)
查看>>
hdu--1698 Just a Hook(线段树+区间更新+懒惰标记)
查看>>
Python学习笔记-EXCEL操作
查看>>
输出保留12位小数的浮点数
查看>>
LnTbtbKLyv
查看>>
springboot ---> spring ioc 注册流程 源码解析 this.prepareContext 部分
查看>>
Java基础随笔
查看>>
图的存储结构
查看>>
图的遍历
查看>>
最小生成树的基本算法
查看>>
MySQL基础操作
查看>>
cf 1004 D Sonya and Matrix
查看>>
求幂塔函数
查看>>
机器学习常用性能度量中的Accuracy、Precision、Recall、ROC、F score等都是些什么东西?...
查看>>
目标检测中常提到的IoU和mAP究竟是什么?
查看>>