我需要连接列content的值。我尝试使用listagg将它们连接起来,但它不起作用。我不知道为什么,因为它不返回错误。可能存在比listtagg更好的选项来连接它们
我有三篇重要的专栏文章:
ID、Step_id、时间戳和内容。当内容长度超过一定长度时,将对其进行拆分。
当内容被划分为id时,step_id相同,但时间戳是其他的。
例如:
Id | step_id | timestamp | content|
1 | A | 15:21:21 | ABCDEFG|
1 | A | 15:21:22 | HIJK|我尝试将其与以下内容联系起来:
Id | step_id | content |
1 | A | ABCDEFGHIJK |我曾尝试使用row_number和连接部件,但它不起作用,这是合乎逻辑的。
我的代码:
With dane as
(
select id,step_id,row_number() over (partition by id, step_id, order by timestamp) as rno, cast(content as varchar(15024)) as content from xya),
dane1 as (select id, content as con1,step_id from dane where rno=1)
dane2 as (select id, content as con2 ,step_id from dane where rno=2)
dane3 as (select id, content as con3 ,step_id from dane where rno=3)
dane4 as (select id, content as con4,step_id from dane where rno=4)
select dane3. id, con1||con2||con3||con4, dane1.step_id from
dane1 left join dane 2 on dane1.id=dane2.id and dane1.step_id=dane2.step_id
left join dane3 on dane3.id=dane2.id and dane3.step_id=dane2.step_id发布于 2021-04-20 07:15:12
试试这个:
select id, step_id, listagg(content)within group(order by timestamp) content
from xya
group by id,step_id;使用测试数据的简单示例:
with xya( Id , step_id , timestamp , content) as (
select 1 , 'A' , '15:21:21' , 'ABCDEFG' from dual union all
select 1 , 'A' , '15:21:22' , 'HIJK' from dual
)
select id, step_id, listagg(content)within group(order by timestamp) content
from xya
group by id,step_id;
ID STEP_ID CONTENT
---------- ------- ------------------------------
1 A ABCDEFGHIJK发布于 2021-04-20 15:34:43
我早些时候试过了,但没有效果。可能是由于格式数据= clob (9750字符)。在正常数据上,它是有效的,但在这种情况下不是。当我尝试使用to-char时来自程序的回答:to-char的参数1的数据类型,长度,od值是无效的SQL code=171 SQLstate=42815驱动程序3.53.95。我在db2上工作
当我运行时没有来自程序的to-char回答时,当应用程序兼容性设置设置为以前的级别时,尝试使用函数。SQLcode =4743 SQLstate =56038驱动程序3.53.95
https://stackoverflow.com/questions/67169930
复制相似问题