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!

Using REGEXP_REPLACE to replace last occurrence of new line character

933417Nov 19 2014 — edited Nov 21 2014

I have to remove  the last occurrence of a new line character or CHR(13) in the below context .

But the regexp_replace is not doing this.My desired output is in 3rd column , where as the output in column 4 (ENAME_LIST) is actually I m getting.

REGEXP_REPALCE seems to be replacing the last alphabetic instead of the last new line character .

Can you please suggest me as how to modify the below query.

SELECT d.deptno,

         d.dname,

         REGEXP_REPLACE (XMLAGG (XMLELEMENT (e,

                             e.ename || CHR(13)

                             ).EXTRACT ('//text()') ORDER BY e.ename).GetClobVal (),'.$') ename_list

    FROM dept d LEFT JOIN emp e ON e.deptno = d.deptno

GROUP BY d.deptno, d.dname

ORDER BY d.deptno, d.dname

DEPTNODNAMEENAME_LIST_DESIREDENAME_LIST
10ACCOUNTING

CLARK

KING

MILLER

CLARK

KING

MILLE

20RESEARCH

ADAMS

FORD

JONES

SCOTT

SMITH

ADAMS

FORD

JONES

SCOTT

SMIT

30SALES

ALLEN

BLAKE

JAMES

MARTIN

TURNER

WARD

ALLEN

BLAKE

JAMES

MARTIN

TURNER

WAR

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 19 2014
Added on Nov 19 2014
3 comments
1,740 views