如何分离; Oracle 中的多行 请在Oracle中编写查询
注意: 分号应该从具有超过 3 或 4 个的输入表中获取..可以扩展到 n 个数字..我们不能假设它。它应该将分号分成多行
我有一张如下所示的表格。
输入:
身份证 | 句子 |
---|---|
1 | 数十万年之后-一句话;那句话/也许是我们最强的方式 |
2 | 虚拟文本块;出版和图形设计;填充页面空白;在实际文字之前/添加 |
输出应该是:
身份证 | 句子 |
---|---|
1 | 数十万之后 |
1 | 年 - 一些句子 |
1 | 那句话/也许是我们最强的办法 |
2 | 虚拟文本块 |
2 | 出版和平面设计 |
2 | 填补页面空白 |
2 | 在实际单词之前/添加 |
任何帮助将不胜感激。
需要用Oracle编写查询
这是示例数据的一个选项
SQL> with test (id, sentence) as
2 (select 1, 'After hundreds of thousands;years - some sentence;the sentence/Perhaps our strongest way' from dual union all
3 select 2, 'dummy block of text;publishing and graphic design;fill gaps in the page;before the actual words / added' from dual
4 )
查询:
5 select id,
6 regexp_substr(sentence, '[^;]+', 1, column_value) sentence
7 from test cross join
8 table(cast(multiset(select level from dual
9 connect by level <= regexp_count(sentence, ';') + 1
10 ) as sys.odcinumberlist))
11 order by id, column_value;
ID SENTENCE
---------- ----------------------------------------------------------------------------------------------------
1 After hundreds of thousands
1 years - some sentence
1 the sentence/Perhaps our strongest way
2 dummy block of text
2 publishing and graphic design
2 fill gaps in the page
2 before the actual words / added
7 rows selected.
SQL>