oracle中常用函数WM_CONCAT(行转列)

WM_CONCAT-列转行函数:
用法: create table T002
(
APPROVAL_NO varchar2(200),
APPROVAL_NAME varchar2(200),
APPROVAL_LINE_NOTE varchar2(200)
)

insert into T002 values('1001','张三','意见一');  
insert into T002 values('1001','李四','意见二');  
insert into T002 values('1001','王五','意见三');  
insert into T002 values('1001','小六','意见四');  
insert into T002 values('1001','小七',null);  
insert into T002 values('1002','小七','意见一');  
insert into T002 values('1002','小八',null);  

select APPROVAL_NO,replace(wm_concat(APPROVAL_NAME || ‘:’ || APPROVAL_LINE_NOTE ),’,’ ,chr(10) || chr(13) ) as note
from T002
where APPROVAL_LINE_NOTE is not null
group by APPROVAL_NO;
结果:APPROVAL_NO note
1001 张三:意见一
李四:意见二
王五:意见三
小六:意见四
1002 小七:意见一

你可能感兴趣的:(oracle)