Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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 如何使用REGEXP_REPLACE检查字符串和REPLACE中是否存在值“Closed”_Sql_Oracle_Regexp Replace_Regexp Substr_Regexp Like - Fatal编程技术网

Sql 如何使用REGEXP_REPLACE检查字符串和REPLACE中是否存在值“Closed”

Sql 如何使用REGEXP_REPLACE检查字符串和REPLACE中是否存在值“Closed”,sql,oracle,regexp-replace,regexp-substr,regexp-like,Sql,Oracle,Regexp Replace,Regexp Substr,Regexp Like,我有以下情况 星期一上午8:30至下午6:00星期二星期三上午8:30至下午6:00休息 这里星期二休息。因此,我需要从字符串“星期二关闭”中排除以下值,并生成为: 星期一上午8:30至下午6:00星期三上午8:30至下午6:00 尝试使用REGEXP_REPLACEOfficeHrs、'Closed'、'',它们只会发出闭合部分,但不确定如何忽略字符串中的您最好使用REGEXP_substr而不是REGEXP_replace,instr、REGEXP_count作为辅助函数,并在末尾使用lis

我有以下情况

星期一上午8:30至下午6:00星期二星期三上午8:30至下午6:00休息

这里星期二休息。因此,我需要从字符串“星期二关闭”中排除以下值,并生成为:

星期一上午8:30至下午6:00星期三上午8:30至下午6:00

尝试使用REGEXP_REPLACEOfficeHrs、'Closed'、'',它们只会发出闭合部分,但不确定如何忽略字符串中的

您最好使用REGEXP_substr而不是REGEXP_replace,instr、REGEXP_count作为辅助函数,并在末尾使用listag进行连接:

with tab as
(
 select 'Monday 8:30 a.m. to 6:00 p.m.
 Tuesday Closed
 Wednesday 8:30 a.m. to 6:00 p.m' as str from dual 
), t1 as
(
select regexp_substr(str,'^.*$',1,level,'m') as str, level as lvl
  from tab
 connect by level <= regexp_count(str,chr(10)) + 1
)
select listagg(str,chr(10)) within group (order by lvl) as "Result String"
  from t1
 where instr(str,'Closed')=0;

Result String
---------------------------------
Monday 8:30 a.m. to 6:00 p.m.
 Wednesday 8:30 a.m. to 6:00 p.m
您可以尝试/[^]*Closed\s?/进行匹配,然后将其替换为 希望它有帮助

您可以试试这个:

 with tab as(
  select 'Monday 8:30 a.m. to 6:00 p.m. <.br> Tuesday Closed <.br> Wednesday 8:30 a.m. to 6:00 p.m.' as str from dual union all
  select 'Monday 8:30 a.m. to 6:00 p.m. <.br> Tuesday Closed <.br> Wednesday 8:30 a.m. to 6:00 p.m. <.br> Thursday Closed <.br> Sunday 8:30 a.m. to 6:00 p.m.' as str from dual union all
  select 'Monday 8:30 a.m. to 6:00 p.m. <.br> Tuesday Closed <.br> Wednesday Closed <.br> Sunday 8:30 a.m. to 6:00 p.m.' as str from dual
)
select regexp_replace(str,'> [[:alpha:]]* Closed <.br')

from tab;

dFabdLe/P>文本总是在字符串的中间吗?图案总是一样的吗?图案是一样的。日子可以改变。任何一天都可以关闭。谢谢,这就像预期的一样工作regexp_replacestr,“[[:alpha:][]*closed”只要是唯一可能的标记,这将工作。。。而且,只要公司关闭的日期不是列表中的第一天或最后一天,这是真的。因为模式总是相同的,所以这不应该是一个问题。问题被标记为SQL和Oracle。前斜杠是怎么回事?这看起来很像sed之类的,与oraclesql完全不同。此外,你认为[^]是什么意思?它所指的是除左括号、小于号、句点、小写字母b、小写字母r、大于号或右括号以外的任何单个字符。这就是你认为的意思吗? | REGEXP_REPLACE(STR,'>[[:ALPHA:]]*CLOSED<.BR') | | :------------------------------------------------------------------------------------------------------- | | Monday 8:30 a.m. to 6:00 p.m. <.br> Wednesday 8:30 a.m. to 6:00 p.m. | | Monday 8:30 a.m. to 6:00 p.m. <.br> Wednesday 8:30 a.m. to 6:00 p.m. <.br> Sunday 8:30 a.m. to 6:00 p.m. | | Monday 8:30 a.m. to 6:00 p.m. <.br> Sunday 8:30 a.m. to 6:00 p.m. |