Oracle 从给定模式中提取双引号字符串
请任何人帮助我 我有一根像 瓦查尔2 b:Oracle 从给定模式中提取双引号字符串,oracle,plsql,Oracle,Plsql,请任何人帮助我 我有一根像 瓦查尔2 b: 'i hav to extract second double queted string "string one".and the "Second one"' 预期结果:第二个 瓦查尔2 a: ' here is "table". "tiger" some other txt '; 预期的结果是老虎 从上面的字符串模式中,我必须提取第二个双引号字符串accurence。在这方面,请帮助我,我在11g中尝试了许多尝试,您可以与新参数一起使用,该参数
'i hav to extract second double queted string "string one".and the "Second one"'
预期结果:第二个
瓦查尔2 a:
' here is "table". "tiger" some other txt ';
预期的结果是老虎
从上面的字符串模式中,我必须提取第二个双引号字符串accurence。在这方面,请帮助我,我在11g中尝试了许多尝试,您可以与新参数一起使用,该参数只允许匹配子表达式:
SQL> with data as (
2 select 'i hav to [...] "string one".and the "Second one"' txt from dual
3 union all
4 select ' here is "table". "tiger" some other txt ' from dual)
5 SELECT regexp_substr(txt,'"([^"]*)"', 1, 2, '', 1) FROM data;
REGEXP_SUBSTR(TXT,'"([^"]*)"',1,2,'',1)
------------------------------------------------------------------------------
Second one
tiger
在10g中,您可以使用replace删除额外的:
在11g中,您可以与只允许匹配子表达式的新参数一起使用:
SQL> with data as (
2 select 'i hav to [...] "string one".and the "Second one"' txt from dual
3 union all
4 select ' here is "table". "tiger" some other txt ' from dual)
5 SELECT regexp_substr(txt,'"([^"]*)"', 1, 2, '', 1) FROM data;
REGEXP_SUBSTR(TXT,'"([^"]*)"',1,2,'',1)
------------------------------------------------------------------------------
Second one
tiger
在10g中,您可以使用replace删除额外的:
您可以使用:
返回:
"tiger"
"Second one"
希望对你有帮助
如果不需要引号,请使用:
REGEXP_REPLACE(x, '^.*".*".*"(.*)".*$', '\1')
您可以使用:
返回:
"tiger"
"Second one"
希望对你有帮助
如果不需要引号,请使用:
REGEXP_REPLACE(x, '^.*".*".*"(.*)".*$', '\1')
使用instr获取字符索引以及获取哪个位置和substr获取字符串的子字符串的示例:
select
substr(str,
instr(str, '"', 1,3)+1,
instr(str, '"', 1, 4)- instr(str, '"', 1,3)-1)
from
(select 'here is "table". "tiger" some other txt' str from dual) strt;
这里substr使用instrstr,“”1,3获取“”的第三次出现。然后它使用instrstr',1,4来获得第四次出现,但我们必须减去第三次出现的位置,因为此参数是要进行减串的文本的大小,即本例中引号之间的文本
您可以改进第四次出现的方式,因为它再次从位置1开始搜索,而不是从位置3开始搜索。使用instr获取字符索引以及获取哪个出现以及substr获取字符串子字符串的示例:
select
substr(str,
instr(str, '"', 1,3)+1,
instr(str, '"', 1, 4)- instr(str, '"', 1,3)-1)
from
(select 'here is "table". "tiger" some other txt' str from dual) strt;
这里substr使用instrstr,“”1,3获取“”的第三次出现。然后它使用instrstr',1,4来获得第四次出现,但我们必须减去第三次出现的位置,因为此参数是要进行减串的文本的大小,即本例中引号之间的文本
您可以改进第四次出现的方式,因为它再次从位置1开始搜索,而不是从位置3开始搜索。+1,尽管regexp\u replace的问题是,如果没有匹配项而不是NULL,它将返回整个字符串。+1,尽管regexp_replace的问题是,如果没有匹配项而不是NULL,它将返回整个字符串。+1很好,没有使用regexps。我可能会这样做:-+1很好,没有使用regexp。我可能会这样做:-