如何分开;复制到Oracle中的多行中[复制]

dldeef67  于 2023-10-16  发布在  Oracle
关注(0)|答案(1)|浏览(89)

此问题已在此处有答案

How to convert comma separated values to rows in oracle?(6个回答)
上个月关门了。

如何分开;请在Oracle中写入查询
**注意:**该字符串应该从输入表中获取超过3或4个...可以扩展到n个数字...我们不能假设它。它应该将字符串分成多行

我有一个表,看起来如下。
输入:
| ID|句话|
| --|--|
| 1 |几十万之后;年-一些刑期;这句话/也许我们最强的方式|
| 2 |虚拟文本块;出版和平面设计;填补页面空白; before the actual words /添加|
输出应为:
| ID|句话|
| --|--|
| 1 |经过数十万|
| 1 |年-一些判决|
| 1 |这句话/也许我们最强的方式|
| 2 |虚拟正文块|
| 2 |出版和平面设计|
| 2 |填补页面空白|
| 2 |before the actual words /添加|
任何帮助将不胜感激。
需要在Oracle中编写查询

yhived7q

yhived7q1#

这里有一个选项,用于示例数据

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>

相关问题