【发布时间】:2020-05-05 21:25:11
【问题描述】:
这是源字符串:
random foobar "name" : "Jack Ryan", other random stuff
在 Oracle 查询中,如何从中提取 Jack Ryan?
我想我正在寻找介于 "name" : " 和 ", 之间的任何内容
【问题讨论】:
标签: sql regex string oracle select
这是源字符串:
random foobar "name" : "Jack Ryan", other random stuff
在 Oracle 查询中,如何从中提取 Jack Ryan?
我想我正在寻找介于 "name" : " 和 ", 之间的任何内容
【问题讨论】:
标签: sql regex string oracle select
一个选项是regexp_replace():
regexp_replace(col, '.*"name" : "([^"]+)".*', '\1')
你也可以使用regexp_substr():
regexp_substr(col, '"name" : "([^"]+)"', 1, 1, null, 1)
这将捕获字符串'"name" : ' 之后的双引号内的字符串部分。
with t as (select 'random foobar "name" : "Jack Ryan", other random stuff' col from dual)
select
col,
regexp_replace(col, '.*"name" : "([^"]+)".*', '\1') newcol1,
regexp_substr(col, '"name" : "([^"]+)"', 1, 1, null, 1) newcol2
from t
色彩 |新科尔1 | NEWCOL2
:------------------------------------------------ ---- | :-------- | :--------
random foobar "name" : "Jack Ryan",其他随机的东西 |杰克瑞恩 |杰克瑞恩
【讨论】:
regexp_substr()并将第四个参数设置为2而不是1。