WMSYS.WM_CONCAT 这个函数,我翻了一下手头上oracle 10g 的官方文档没找到。在国内搜索,搜到内容差不多,信息量最多不外乎是如下结果:http://blog.csdn.net/wh62592855/archive/2009/10/29/4745581.aspx 。
但是我在本机oracle10g r2 上运行,用over (partition by id) ,系统提示不能使用。有没有谁关于WMSYS.WM_CONCAT的详细介绍啊,英文也可以。PS:
在国外的一个帖子中,看到有说ListAgg函数更好,可以定义连接字符串内部顺序,有谁用过吗?我的oracle版本好像没这个函数
但是我在本机oracle10g r2 上运行,用over (partition by id) ,系统提示不能使用。有没有谁关于WMSYS.WM_CONCAT的详细介绍啊,英文也可以。PS:
在国外的一个帖子中,看到有说ListAgg函数更好,可以定义连接字符串内部顺序,有谁用过吗?我的oracle版本好像没这个函数
解决方案 »
- 数据泵导出数据报错50分求大神解救
- oracle 存储过程 关于游标的一个问题请教
- oracle 用户登入外部认证
- Oracle存储过程捕获异常
- 请教一个导入oracle9i数据库的问题。
- 大侠们进来那分:jdbc(或ado吧)这些客户端访问本机的oracle服务,是否使用ipc协议比用tcp协议访问127.0.0.1的效果要
- 导数据时间问题?
- 请问Oracle 的一个表里最多能存多少记录,对速度有影响吗???
- 分已经结过了,继续问:这个语句如何改成ORACLE?
- 改了表结构,与表结构关联的过程,trigger都必须更新吗?关键是都必须更新吗?
- 一个select语句,where条件是有选择的添加,怎么写?
- 这个该怎么写
SQL> create table IDTABLE
2 (
3 id number,
4 val varchar2(20)
5 )
6 ;Table createdSQL>
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'abc');1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'abc');1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'def');1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'def');1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'ghi');1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'jkl');1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'mno');1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'mno');1 row insertedSQL> select id,val from idtable; ID VAL
---------- --------------------
10 abc
10 abc
10 def
10 def
20 ghi
20 jkl
20 mno
20 mno8 rows selectedSQL> commit;Commit completeSQL>
SQL> SELECT ID, WMSYS.WM_CONCAT(VAL) AS ENAMES
2 FROM IDTABLE
3 GROUP BY ID; ID ENAMES
---------- --------------------------------------------------------------------------------
10 abc,abc,def,def
20 ghi,jkl,mno,mnoSQL>
SQL> SELECT ID, WMSYS.WM_CONCAT(DISTINCT VAL) AS ENAMES
2 FROM IDTABLE
3 GROUP BY ID
4 ORDER BY ID; ID ENAMES
---------- --------------------------------------------------------------------------------
10 abc,def
20 ghi,jkl,mnoSQL>
SQL> SELECT ID, VAL, WMSYS.WM_CONCAT(VAL) OVER(PARTITION BY ID) AS ENAMES
2 FROM IDTABLE
3 ORDER BY ID; ID VAL ENAMES
---------- -------------------- --------------------------------------------------------------------------------
10 abc abc,abc,def,def
10 abc abc,abc,def,def
10 def abc,abc,def,def
10 def abc,abc,def,def
20 ghi ghi,jkl,mno,mno
20 jkl ghi,jkl,mno,mno
20 mno ghi,jkl,mno,mno
20 mno ghi,jkl,mno,mno8 rows selectedSQL>
SQL> SELECT ID, VAL, WMSYS.WM_CONCAT(VAL) OVER(ORDER BY ID, VAL) AS ENAMES
2 FROM IDTABLE
3 ORDER BY ID; ID VAL ENAMES
---------- -------------------- --------------------------------------------------------------------------------
10 abc abc,abc
10 abc abc,abc
10 def abc,abc,def,def
10 def abc,abc,def,def
20 ghi abc,abc,def,def,ghi
20 jkl abc,abc,def,def,ghi,jkl
20 mno abc,abc,def,def,ghi,jkl,mno,mno
20 mno abc,abc,def,def,ghi,jkl,mno,mno8 rows selected
行转列
tb
id name
1 a
1 b
2 c
2 d
3 eselect id,wm_concat(name) from tb group by id结果
id name
1 a,b
2 c,d
3 e
1 c
1 b
1 aselect id,wm_concat(name) from tb group by id结果是:
id name
1 c,b,a 有方法出来这个 效果吗:1 a,b,c
SQL> select * from www_1;
ID NAME
-- ----------
1 c
1 b
1 a
SQL> select id,wm_concat(name) from (select * from www_1 order by id,name) group by id;
ID WM_CONCAT(NAME)
-- --------------------------------------------------------------------------------
1 a,b,c
SQL>
Name Type Nullable Default Comments
---- ------ -------- ------- --------
ID NUMBER Y
NAME NUMBER Y
SQL> select * from IDTABLE;
ID NAME
---------- ----------
1 1
1 2
1 3
1 24
1 17
1 16
6 rows selected
SQL> select id,WMSYS.WM_CONCAT(name) from
2 (select * from IDTABLE order by id,name) y group by id ;
ID WMSYS.WM_CONCAT(NAME)
---------- --------------------------------------------------------------------------------
1 1,2,3,17,24,16
SQL>
select id,max(name) from (select id,wm_concat(name)over(partition by id order by name asc) name from www_1) group by id;
ID WM_CONCAT(NAME)
-- --------------------------------------------------------------------------------
1 a,b,c,r,t,e
SQL> select id,max(name) from (select id,wm_concat(name)over(partition by id order by name asc) name from www_1) group by id ;
ID MAX(NAME)
-- --------------------------------------------------------------------------------
1 a,b,c,e,r,t