xmlagg function returning seperator two times if value is null
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