Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何在Oracle中提取两个单词之间的文本_Sql_Regex_String_Oracle_Select - Fatal编程技术网

Sql 如何在Oracle中提取两个单词之间的文本

Sql 如何在Oracle中提取两个单词之间的文本,sql,regex,string,oracle,select,Sql,Regex,String,Oracle,Select,这是源字符串: random foobar "name" : "Jack Ryan", other random stuff 在Oracle查询中,如何从中提取Jack Ryan 我想我在寻找介于“name”:“和”之间的任何东西,一个选项是regexp\u replace(): 您还可以使用regexp\u substr(): 这将捕获字符串“name”:“”后面双引号内的字符串部分 : with t as (select 'random foobar "name" : "Jack Ryan

这是源字符串:

random foobar "name" : "Jack Ryan", other random stuff
在Oracle查询中,如何从中提取Jack Ryan


我想我在寻找介于
“name”:“
”之间的任何东西,

一个选项是
regexp\u replace()

您还可以使用
regexp\u substr()

这将捕获字符串
“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
COL | NEWCOL1 | NEWCOL2 :----------------------------------------------------- | :-------- | :-------- 随机foobar“名称”:“Jack Ryan”,其他随机的东西| Jack Ryan | Jack Ryan
谢谢接下来的问题-如果我需要找到此模式的第二个实例,该怎么办?@Studiod:您可以使用
regexp\u substr()
并将第四个参数设置为
2
,而不是
1
regexp_substr(col, '"name" : "([^"]+)"', 1, 1, null, 1)
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
COL | NEWCOL1 | NEWCOL2 :----------------------------------------------------- | :-------- | :-------- random foobar "name" : "Jack Ryan", other random stuff | Jack Ryan | Jack Ryan