oracle列转行 WM_CONCAT LISTAGG

开发给个SQL说给某个条件时报ORA-22922

代码段:

1 SELECT 袋号,
2                     SUM(实际重量) AS 实际重量,
3                     SUM(材积重量) AS 材积重量,
4                     COUNT(运单号) AS 件数,
5                     TO_CHAR(WMSYS.WM_CONCAT(运单号)) AS 运单编号
6                FROM TBL
7               GROUP BY 袋号

修改成如下后解决:

1 SELECT 袋号,
2        SUM(实际重量) AS 实际重量,
3        SUM(材积重量) AS 材积重量,
4        COUNT(运单号) AS 件数,
5        LISTAGG(运单号, ‘,‘) WITHIN GROUP(ORDER BY 运单号) AS 运单编号
6   FROM TBL
7  GROUP BY 袋号

注:

LISTAGG为11G2才提供的函数

时间: 2024-12-24 23:45:00

oracle列转行 WM_CONCAT LISTAGG的相关文章

Oracle 列转行函数 Listagg()

这是一个Oracle的列转行函数:LISTAGG() 先看示例代码: Sql代码   with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Shanghai' city from dual union all select 'China' nation ,'Beijing' city from dual union all select 'USA' nat

oracle 列转行函数listagg、判断函数decode

1.decode 使用decode判断字符串是否一样 DECODE(value,if1,then1,if2,then2,if3,then3,...,else) decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 某些场景可以代替case when 2.listagg 首先看下数据情况 想把这个人的阶段列转成一行分隔显示使用listagg函数 select listagg (decode(sts,'A',coll_stage),',') within group (

Oracle列转行函数版本不兼容解决方案

业务场景 本博客记录一下Oracle列转行函数在Oracle11的一些不兼容问题,vm_concat在一些业务场景是必须的.不过这个函数使用要谨慎,底层实现应该也是group by等等实现的,性能并不是特别好.这个函数在Oracle12是没有的,在Oracle11是不太兼容的,Oracle10可以正常使用.最近遇到这个问题,网上博客很多都写到了自定义列转行函数的办法去解决.但是这种办法并不一定适用所有的业务场景.我并没有采用.不过有些场景还是可以使用的. 网上优秀例子 下面是网络记录比较详细的例

oracle 列转行

with temp as( select 'A01' nation ,1 as S1,2 as S2, 3 as S3 from dual union all select 'A02' nation ,null as S1,5 as S2, 6 as S3 from dual ) select * from temp unpivot(Qty for Sizes in(s1,s2,s3))

oracle 行转列、列转行

最近做数据处理,经常遇到需要行转列.列转行的场景,记录个非常简单实用的oracle  列转行.行转的列方法 1.行转列,基础数据如下 做行转列处理 处理SQL select user_name,max(date_201501) as date_201501,max(date_201502),max(date_201503),max(date_201504) from (select t.user_name,case when t.acct_date = '201501' then t.flow

Oracle行转列、列转行的Sql语句总结(转)

多行转字符串 这个比较简单,用||或concat函数可以实现 select concat(id,username) str from app_userselect id||username str from app_user 字符串转多列 实际上就是拆分字符串的问题,可以使用 substr.instr.regexp_substr函数方式 字符串转多行 使用union all函数等方式 wm_concat函数 首先让我们来看看这个神奇的函数wm_concat(列名),该函数可以把列值以",&quo

Oracle 行转列、列转行 的Sql语句总结

参考文章:http://blog.csdn.net/tianlesoftware/article/details/4704858 多行转字符串 这个比较简单,用||或concat函数可以实现 select concat(id,username) str from app_user select id||username str from app_user 字符串转多列 实际上就是拆分字符串的问题,可以使用 substr.instr.regexp_substr函数方式 字符串转多行 使用union

Oracle行转列、列转行的Sql语句总结

多行转字符串 这个比较简单,用||或concat函数可以实现 ?SQL Code? 12 ? select?concat(id,username)?str?from?app_userselect?id||username?str?from?app_user 字符串转多列 实际上就是拆分字符串的问题,可以使用 substr.instr.regexp_substr函数方式 字符串转多行 使用union all函数等方式 wm_concat函数 首先让我们来看看这个神奇的函数wm_concat(列名)

oracle行转列,列转行

多行转字符串这个比较简单,用||或concat函数可以实现 SQL Code select concat(id,username) str from app_userselect id||username str from app_user字符串转多列实际上就是拆分字符串的问题,可以使用 substr.instr.regexp_substr函数方式字符串转多行使用union all函数等方式wm_concat函数首先让我们来看看这个神奇的函数wm_concat(列名),该函数可以把列值以",&q