I have a table which contains data something like this:
CREATE TABLE UDA_DATA
( uda VARCHAR2(20),
value_text VARCHAR2(4000)
);
Insert into UDA_DATA values('Material_ID','PBL000129 PBL000132 PBL000130 PBL000131 PBL000133');
Insert into UDA_DATA values('Material_ID','PBL0001341 PBL0001381 PBL0001351 PBL0001361 PBL0001371');
commit;
Now if we select the data from this table it will give the result something like this:
select * from UDA_DATA;
It gives result something like this:
But however I am expecting something like this:
Means it should break the value_text into two or more rows if the character length is more than 30. Also, uda column should have the suffix as 1,2..n and it should not break the text in between.
Wrote a recurvise CTE to acheive the result:
with rcte (rn, uda, value, chunk_num, value_text) as (
select rownum,
uda,
substr(value_text, 1, 30),
1,
substr(value_text, 31)
from uda_data
union all
select rn,
uda,
substr(value_text, 1, 30),
chunk_num + 1,
substr(value_text, 31)
from rcte
where value_text is not null
)
select uda || chunk_num as uda, value
from rcte
order by rn, chunk_num;
Which is giving the result like this:
In third row, it's breaking the text in between which is not correct, want a result something this:
Anyhelp will be highly appreciated.



