为了账号安全,请及时绑定邮箱和手机立即绑定

oracle WMSYS.WM_CONCAT 函数转为listagg?

oracle WMSYS.WM_CONCAT 函数转为listagg?

有只小跳蛙 2019-04-19 19:11:27
oracle WMSYS.WM_CONCAT 函数转为listagg
查看完整描述

4 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

NVL2(expr1,expr2,expr3) 功能:如果参数表达式expr1值为NULL,则NVL2()函数返回参数表达式expr3的值;如果参数表达式expr1值不为NULL,则NVL2()函数返回参数表达式expr2的值。NVL( string1, replace_with) 功能:如果string1为NULL,则NVL函数返回replace_with的值,否则返回string1的值,如果两个参数都为NULL ,则返回NULL。

查看完整回答
反对 回复 2019-04-23
?
千万里不及你

TA贡献1784条经验 获得超9个赞

所有版本的oracle都可以使用wm_concat()函数 。例:select wm_concat(name) as name from user;

但如果是oracle11g,使用listagg() within group()函数 。例:select listagg(name, ‘,’) within group( order by name) as name from user;

使用wm_Concat:

使用ListAgg:

结果:



查看完整回答
反对 回复 2019-04-23
?
侃侃尔雅

TA贡献1801条经验 获得超15个赞

select wm_concat(name) name from user;--10g写法
select listagg(name,',') within group (order by name) name from user;--11g写法

查看完整回答
反对 回复 2019-04-23
?
达令说

TA贡献1821条经验 获得超6个赞

方法一,使用connect by +sys_connect_by_path :
--测试数据
create table test(col varchar2(10));
insert into test values('a');
insert into test values('b');
insert into test values('c');
--SQL语句:
select ltrim(sys_connect_by_path(col, ','), ',')
from (select col, row_number() over(order by rownum) rn from test t)
where connect_by_isleaf = 1
start with rn = 1
connect by rn = prior rn + 1;
方法二,使用xmltype:
select dbms_lob.substr(rtrim(xmlagg(xmlparse(content col || ',' wellformed))
.getclobval(),
','),
4000,
1)
from test;
另外在10,11版本中也不建议使用wm_concat,这个函数属于非公开函数,在12c版本中已经失效;


查看完整回答
反对 回复 2019-04-23
  • 4 回答
  • 0 关注
  • 1521 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信