作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
甲骨文中有像listunagg函数这样的东西吗?例如,如果我有类似的数据:
------------------------------------------------------------
| 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 |
-----------------------------------------------
最佳答案
正如@be现在已经在注释中指出的那样,Oracle不提供此类功能。因此,作为一种快速的解决方法,您可以编写类似的查询:
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
关于string - listunagg函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13189575/
我是一名优秀的程序员,十分优秀!