【发布时间】:2017-06-28 08:29:34
【问题描述】:
我想生成一个表,其中包含另一个表的子字符串和 ID,子字符串出现在该表中。见问题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
table_expressions 包含所需的子字符串
我的真实数据产生了很多要连接的 ID。使用真实数据运行代码后,出现错误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.。
如何重写代码以将结果列IDs 格式化为 CLOB 格式?
我查看了问题Listagg function,但我不明白发布答案中的代码。
这段代码:
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
;
产生错误FROM keyword not found where expected。
我想生成一个表 a_y,它应该看起来像这样,列 A 和 IDs 应该是 clob 格式:
A | IDs
-----------------------------|-------
atveroeosipsum | 1,3
test | 2
stetclitakasd | 2
noseatakimata | 3
loremipsumdolor | 1,4
consetetursadipscingelitr | 5
我该如何解决这个问题?
【问题讨论】:
-
table_expressions中的字符串片段必须是CLOB吗?它们是相对较短的字符串(不超过 4000 个字符)似乎是有道理的。 -
它们可能比这更长。真实数据的列在 CLOB 中。
标签: oracle concatenation clob