Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

xmlagg function returning seperator two times if value is null

user546710Apr 30 2012 — edited May 31 2012
Hi all,

I am using xmlagg function to concatenate the values. If concatenated field is having NULL value, the seperator is coming two times.
Please see the sample data below.

CREATE TABLE emp
(
empno NUMBER,
deptno NUMBER(2)
);

INSERT INTO EMP VALUES (1, 10);
INSERT INTO EMP VALUES (1, 20);
INSERT INTO EMP(empno) VALUES (1);
INSERT INTO EMP VALUES (1, 30);

INSERT INTO EMP VALUES (2, 10);
INSERT INTO EMP VALUES (2, 20);
INSERT INTO EMP(empno) VALUES (2);
INSERT INTO EMP VALUES (2, 40);

select rtrim (xmlagg (xmlelement (e, deptno || '; ')).extract ('//text()'), '; ') from emp group by empno
Output --> 10; 30; ; 20
*10; 40; ; 20*

Oracle version is
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

I dont want to display the seperator two times, if NULL value is there in the concatenated column.

Thanks in advance.

Tahnks,
Pal
This post has been answered by odie_63 on Apr 30 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 28 2012
Added on Apr 30 2012
4 comments
2,185 views