listunagg function?(列表功能?)
本文介绍了列表功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
oracle 中是否有类似 listunagg 函数的东西?例如,如果我有这样的数据:
is there such thing in oracle like listunagg function? For example, if I have a data like:
user_id | degree_fi | degree_en | degree_sv |
---|---|---|---|
3601464 | 3700 | 1600 | 2200 |
1020 | 100 | 0 | 0 |
3600520 | 100,3200,400 | 1300、800、3000 | 1400、600、1500 |
3600882 | 0 | 100 | 200 |
我想显示这样的数据:
user_id | degree_fi | degree_en | degree_sv |
---|---|---|---|
3601464 | 3700 | 1600 | 2200 |
1020 | 100 | 0 | 0 |
3600520 | 100 | 1300 | 1400 |
3600882 | 0 | 100 | 200 |
3600520 | 3200 | 800 | 600 |
3600520 | 400 | 3000 | 1500 |
我试图找到一些与 listagg
相反的函数,但找不到.
I tried to find some function like opposite of listagg
but couldn't find any.
推荐答案
正如@be here 现在已经在评论中指出的,Oracle 不提供这样的功能.因此,作为一种快速解决方法,您可以编写类似的查询:
As @be here now has already noted in the comment Oracle doesn't provide such a function. So as a quick workaround you could write similar query:
with t1(user_id, degree_fi, degree_en, degree_sv) as
(
select 3601464, '3700', '1600', '2200' from dual union all
select 1020 , '100' , '0' , '0' from dual union all
select 3600520, '100,3200,400', '1300, 800, 3000', '1400, 600, 1500' from dual union all
select 3600882, '0', '100', '200' from dual
),
Occurence(ocr) as(
select Level as ocr
from (select max(greatest(regexp_count(degree_fi, '[^,]+')
, regexp_count(degree_en, '[^,]+')
, regexp_count(degree_sv, '[^,]+')
)
) mx
from t1
)
connect by level <= mx
)
select *
from (
select User_id
, regexp_substr(degree_fi, '[^,]+', 1, o.ocr) as degree_fi
, regexp_substr(degree_en, '[^,]+', 1, o.ocr) as degree_en
, regexp_substr(degree_sv, '[^,]+', 1, o.ocr) as degree_sv
from t1 t
cross join Occurence o
)
where degree_fi is not null
or degree_en is not null
or degree_sv is not null
结果:
User_Id Degree_Fi Degree_En Degree_Sv
------------------------------------------------------------
3601464 3700 1600 2200
1020 100 0 0
3600520 100 1300 1400
3600882 0 100 200
3600520 3200 800 600
3600520 400 3000 1500
这篇关于列表功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:列表功能?


基础教程推荐
猜你喜欢
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01