【发布时间】:2013-07-30 15:57:41
【问题描述】:
我有一张类似这样的表:
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
我目前被困在这里。
【问题讨论】:
-
在一列中存储多个值是糟糕的数据库设计,最好的办法是更改设计,但如果它不可行,我会看看我是否可以编写一些 SQL 来帮助
-
谢谢。目前给出了数据库设计。因为它不是生产数据库,所以我想它目前是可以接受的。
标签: sql regex plsql oracle11gr2