sql - Monitoring data with delimiter to create a new rows
问题描述
I want to create a rows from one row on table that contains a delimiter on some fields as mentioned below on screen shoot
I want a result A separalte rows for the rows that already contains a deleimiter ;
the inputs are data from table 1 and the output is data as mentionned below on table 2 using oracle sql :insert and select query
you can see below the output recommanded:
解决方案
或者:
SQL> with test (id, description, val, after, before) as
2 -- you already have sample data and don't type this
3 (select 1, 'ARTIC1;ARTIC2;ART11', '15;2;3', '12;6;8', '13;7;12' from dual union all
4 select 2, 'ARTICLE3;ARTICLE4' , '3;5' , '10;23' , '12;25' from dual union all
5 select 3, 'ARTICLE 5' , '6' , '2' , '1.9' from dual
6 )
7 -- query that does the job begins here
8 select id,
9 regexp_substr(description, '[^;]+', 1, column_value) descr,
10 regexp_substr(val , '[^;]+', 1, column_value) val,
11 regexp_substr(after , '[^;]+', 1, column_value) after,
12 regexp_substr(before , '[^;]+', 1, column_value) before
13 from test cross join
14 table(cast(multiset(select level from dual
15 connect by level <= regexp_count(description, ';') + 1
16 ) as sys.odcinumberlist))
17 order by id, descr, val;
ID DESCR VAL AFTER BEFORE
---------- ---------- ---------- ---------- ----------
1 ARTIC1 15 12 13
1 ARTIC2 2 6 7
1 ART11 3 8 12
2 ARTICLE3 3 10 12
2 ARTICLE4 5 23 25
3 ARTICLE 5 6 2 1.9
6 rows selected.
SQL>
推荐阅读
- excel - 使用 Azure 数据工厂将 Excel OneDrive 转换为 Blob
- php - PHP多维数组使用另一个值按值搜索
- p5.js - 如何使用 p5.js /p5.play 让所有精灵移动到不同的吸引力点
- r - 使用 scale_x_datetime() 设置限制会在 ggplot 中静默放置条形图
- java - spring cloud stream - StreamBridge - 当远程目的地没有人消费消息时,消息不会进入DLQ
- c++ - 使用标记值和计数器控制从文件中获取数据
- node.js - 在 Flutter 中显示 JSON 数据
- c++ - 无法使用 lambda 初始化模板 constexpr 成员变量
- .net - 在 Refit Proxy 和 DelegatingHandler 之间传递值
- javascript - 仅当数组值与对象数组键匹配时如何获取对象数组