oracle WMSYS.WM_CONCAT 函数转为listagg?

oracle WMSYS.WM_CONCAT 函数转为listagg


有只小跳蛙
浏览 1527回答 4
4回答

holdtom

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

千万里不及你

所有版本的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:结果:

侃侃尔雅

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

达令说

方法一,使用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 = 1start with rn = 1connect 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版本中已经失效;
打开App,查看更多内容
随时随地看视频慕课网APP