Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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
替换PL/SQL中的几行regexp函数_Sql_Regex_Oracle_Plsql - Fatal编程技术网

替换PL/SQL中的几行regexp函数

替换PL/SQL中的几行regexp函数,sql,regex,oracle,plsql,Sql,Regex,Oracle,Plsql,有没有办法从字符串中删除几行? 我有一个varchar值,其中包含大量字符串: declare v_txt varchar(4000); v_txt2 varchar(4000); begin v_txt := '<Html> <Head> <meta charset="windows-1251" /> <style> div {text-indent

有没有办法从字符串中删除几行? 我有一个varchar值,其中包含大量字符串:

declare
  v_txt varchar(4000);
  v_txt2 varchar(4000);
begin
  v_txt := '<Html>
          <Head>
          <meta charset="windows-1251" />
          <style>
             div {text-indent: 40px;}
          </style>
          <style>
             p {text-indent: 40px;}
          </style>
          </Head>
          <Body>
          <font face="Arial">'

  select regexp_replace(v_txt, some_pattern, '') into v_txt2 from dual;
  dbms_output.put_line(v_txt2);
end;
我需要删除第一个'style'标记和最后一个'/style'标记之间的行吗?
我如何实现它?使用什么样的模式?

您不需要使用REGEXP:

with t(val) as(
  select '<Html>
          <Head>
          <meta charset="windows-1251" />
          <style>
             div {text-indent: 40px;}
          </style>
          <style>
             p {text-indent: 40px;}
          </style>
          </Head>
          <Body>
          <font face="Arial">' from dual 
)
select substr(val, instr(val, '<style>'), instr(val, '</style>', -1, 1) - instr(val, '<style>', 1, 1) + length('</style>')) val
  from t

                                      VAL
---------------------------------------------------------------------------------
<style> div {text-indent: 40px;} </style> <style> p {text-indent: 40px;} </style>

您不需要使用REGEXP:

with t(val) as(
  select '<Html>
          <Head>
          <meta charset="windows-1251" />
          <style>
             div {text-indent: 40px;}
          </style>
          <style>
             p {text-indent: 40px;}
          </style>
          </Head>
          <Body>
          <font face="Arial">' from dual 
)
select substr(val, instr(val, '<style>'), instr(val, '</style>', -1, 1) - instr(val, '<style>', 1, 1) + length('</style>')) val
  from t

                                      VAL
---------------------------------------------------------------------------------
<style> div {text-indent: 40px;} </style> <style> p {text-indent: 40px;} </style>

您不需要使用REGEXP:

with t(val) as(
  select '<Html>
          <Head>
          <meta charset="windows-1251" />
          <style>
             div {text-indent: 40px;}
          </style>
          <style>
             p {text-indent: 40px;}
          </style>
          </Head>
          <Body>
          <font face="Arial">' from dual 
)
select substr(val, instr(val, '<style>'), instr(val, '</style>', -1, 1) - instr(val, '<style>', 1, 1) + length('</style>')) val
  from t

                                      VAL
---------------------------------------------------------------------------------
<style> div {text-indent: 40px;} </style> <style> p {text-indent: 40px;} </style>

您不需要使用REGEXP:

with t(val) as(
  select '<Html>
          <Head>
          <meta charset="windows-1251" />
          <style>
             div {text-indent: 40px;}
          </style>
          <style>
             p {text-indent: 40px;}
          </style>
          </Head>
          <Body>
          <font face="Arial">' from dual 
)
select substr(val, instr(val, '<style>'), instr(val, '</style>', -1, 1) - instr(val, '<style>', 1, 1) + length('</style>')) val
  from t

                                      VAL
---------------------------------------------------------------------------------
<style> div {text-indent: 40px;} </style> <style> p {text-indent: 40px;} </style>
使用regexp的解决方案:

select regexp_replace(v_txt, '<style>.*</style>', '[REPLACED]', 1, 1, 'n') into v_txt2 from dual;
结果是:

<Html>
          <Head>
          <meta charset="windows-1251" />
          [REPLACED]
          </Head>
          <Body>
          <font face="Arial">
使用regexp的解决方案:

select regexp_replace(v_txt, '<style>.*</style>', '[REPLACED]', 1, 1, 'n') into v_txt2 from dual;
结果是:

<Html>
          <Head>
          <meta charset="windows-1251" />
          [REPLACED]
          </Head>
          <Body>
          <font face="Arial">
使用regexp的解决方案:

select regexp_replace(v_txt, '<style>.*</style>', '[REPLACED]', 1, 1, 'n') into v_txt2 from dual;
结果是:

<Html>
          <Head>
          <meta charset="windows-1251" />
          [REPLACED]
          </Head>
          <Body>
          <font face="Arial">
使用regexp的解决方案:

select regexp_replace(v_txt, '<style>.*</style>', '[REPLACED]', 1, 1, 'n') into v_txt2 from dual;
结果是:

<Html>
          <Head>
          <meta charset="windows-1251" />
          [REPLACED]
          </Head>
          <Body>
          <font face="Arial">

你给了我一个好主意。谢谢。我已经实现了我想要的。你给了我一个好主意。谢谢。我已经实现了我想要的。你给了我一个好主意。谢谢。我已经实现了我想要的。你给了我一个好主意。谢谢。我已经实现了我想要的。