I want to produce a table which contains substrings and IDs of another table, where the substrings occur. See question Concatenate values.
create table table_expressions
(
A clob
);
insert all
into table_expressions (a) values ('atveroeosipsum')
into table_expressions (a) values ('test')
into table_expressions (a) values ('stetclitakasd')
into table_expressions (a) values ('noseatakimata')
into table_expressions (a) values ('loremipsumdolor')
into table_expressions (a) values ('consetetursadipscingelitr')
select * from dual;
create table a_x
(
A clob,
B clob
);
insert all
into a_x (a, b) values('atveroeosipsumloremipsumdolor', 1)
into a_x (a, b) values('stetclitakasdtest', 2)
into a_x (a, b) values('noseatakimataatveroeosipsum', 3)
into a_x (a, b) values('loremipsumdolor', 4)
into a_x (a, b) values('consetetursadipscingelitr', 5)
select * from dual;
create table a_y
as
with
input_strings ( a ) as (
select column_value from table_expressions
)
select t2.a, listagg(t1.b, ',') within group (order by t1.b)
as ids from a_x t1 join input_strings t2 on t1.a like '%' || t2.a || '%'
group by t2.a
The table_expressions
contains the desired substrings
My real data produce quite a lot IDs to be concatenated. After running the code with the real data the error 01489. 00000 - "result of string concatenation is too long"
*Cause: String concatenation result is more than the maximum size.
*Action: Make sure that the result is less than the maximum size.
occurs.
How could I rewrite the code in order to format the resulting column IDs
in CLOB format?
I looked at question Listagg function but I didn't understand the code in the posted answer.
This code:
create table a_y
as
with
input_strings ( a ) as (
select a
from table_expressions
)
select t2.a, RTRIM(XMLAGG(XMLELEMENT(E,t1.a,',').EXTRACT('//text()') ORDER BY t1.a).GetClobVal(),',') AS LIST as ids
from a_x t1
join input_strings t2 on t1.a like '%' || t2.a || '%'
group by t2.a
;
produces error FROM keyword not found where expected
.
I would like to produce a table a_y, which should look like that and columns A
ans IDs
should be in clob format:
A | IDs
-----------------------------|-------
atveroeosipsum | 1,3
test | 2
stetclitakasd | 2
noseatakimata | 3
loremipsumdolor | 1,4
consetetursadipscingelitr | 5
How can I fix this?