0

我有一个类似的表:

with tab as(
select 'P710345,P345123 are not valid' m from dual
union all
select 'P901236,P234098,P675001 are not valid' m from dual)
select * from tab

我需要的是提取以开头的P字符串并将这些字符串放入同一行的新列中。

最后结果:

P710345,P345123 are not valid         | P710345 | P345123 |        |
P901236,P234098,P675001 are not valid | P901236 | P234098 |P675001 |

我试图提取regexp_substr

with tab as(
select 'P710345,P345123 are not valid' m from dual
union all
select 'P901236,P234098,P675001 are not valid' m from dual )
select regexp_substr (m,'P\d\w+','2') b from tab

我目前被困在这里。

4

1 回答 1

0

我发现最简单的解决方法是制作一个 csv,然后将其导入或在 speedsheet 程序中使用

SELECT CONCAT(
  "'", m, "';'", 
  REPLACE(
     SUBSTR(m, 1, POSITION(' ' IN m)), 
     ',', 
     "';'"), 
  "';") 
FROM ( SELECT 'P710345,P345123 are not valid' AS m FROM DUAL UNION ALL SELECT 'P901236,P234098,P675001 are not valid' AS m FROM DUAL) AS t;
于 2013-07-30T16:13:10.630 回答