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!

Split string field and append new values to the splitted strings

User_1KK7KDec 17 2020 — edited Dec 17 2020

Hi,

I am having scenario where I want to split a single string based on the new line character and append a tag.(If blank string in a line tags with empty string should be there)

eg-
Input =
'12 abc' || chr(10) || '3' || chr(10) ||chr(10) || '3'
Output=
<a>12 abc</a><a>3</a><a></a><a>3</a>

I have written a function to achieve this as follows
Declare
Str varchar2(1000) := '12' || chr(10) || '3' || chr(10) ||chr(10) || '3';
Outstr varchar2(2000);
Begin
For i in 1.. (regexp_count(str, chr(10)) + 1)
loop
Outstr := outstr || '<a>' || regexp_substr(str, '[^,]+||chr(10)',1,i) || '</a>';
End loop;
Dbms_output.put_line(outstr);
End;

But the result I get is
<a>12 abc
3
3</a><a></a><a></a><a></a>

How can I fix this issue(I dont want to use any select statement either only loop)?

This post has been answered by Frank Kulash on Dec 17 2020
Jump to Answer

Comments

Post Details

Added on Dec 17 2020
3 comments
581 views