oracle数据库 wm_concat()函数学习笔记

前端之家收集整理的这篇文章主要介绍了oracle数据库 wm_concat()函数学习笔记前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

wm_concat()函数的作用是 行转列

测试数据:

  1. drop table test;
  2. create table test(a varchar2(30),b varchar2(30),c varchar2(30));
  3. insert into test values('aaa','1','a');
  4. insert into test values('bbb','2','a');
  5. insert into test values('ccc','5','a');
  6. insert into test values('ddd','3','a');
  7. insert into test values('aaaaa','11','b');
  8. insert into test values('bbbbb','22','b');
  9. insert into test values('ccccc','55','b');
  10. insert into test values('ddddd','33','b');
  1. select wm_concat(a) from test

会得到一个CLOB数据(就是大文本字段) 在sqlDeveloper可以点数据边上的...来查看数据

或者用to_char()包裹wm_concat(a)

  1. select to_char(wm_concat(a)) from test

这样可以直接显示出来数据

当你在select中多次使用wm_concat(),会出现数据没有一一对应

解决方法(还是用上面的测试数据):

  1. select c,max(a),max(b) from (
  2. select c,to_char(wm_concat(a) over (partition by c order by a)) a,to_char(wm_concat(b) over (partition by c order by a)) b from test
  3. ) tt
  4. group by c;

超级牛皮的oracle的分析函数over(Partition by...) 及开窗函数

http://www.cnblogs.com/sumsen/archive/2012/05/30/2525800.html

猜你在找的Oracle相关文章