繁体   English   中英

Oracle Regexp_replace字符串

[英]Oracle Regexp_replace string

假设我有以下字符串:

 notNull(devhx_8_other2_name_2) AND notNull(devhx_8_other2_amt) 

如何使用regexp_replace将其更改为:

 (devhx_8_other2_name_2) is not null AND (devhx_8_other2_amt) is not null 

采用

regexp_replace(col, 'notNull(\([^)]+\))', '\1 is not null', 1, 0)

这将查找“ notNull”,后跟一个左括号,其他字符和一个右括号。 它用包括括号的字符串替换,但不带'notNull'并附加'not not null'。

您可以使用以下模式:

  • notNull匹配字符串
  • ( -启动一个捕获组
  • \\(.+?\\) -匹配一个右括号,然后匹配一个或多个字符,但要尽可能少,直到匹配一个右括号
  • ) -捕获组的末尾。

然后将其替换为\\1 is not null ,这将用\\1替换第一个捕获组中匹配的值。 像这样:

SELECT REGEXP_REPLACE(
         your_column,
         'notNull(\(.+?\))',
         '\1 is not null'
       )
FROM   your_table

假设您的字符串始终采用您显示的格式,则不需要正则表达式:

replace( replace( yourString, ')', ') is not null '), 'notNull', '')

使用以下regexp_replace函数:

regexp_replace(regexp_replace(string_name,"notNull",""),"')","') is not null")

在这里,我将'notNull'替换为非空格,即'',然后将右方括号(''')替换为右方括号,一个空格,并输入文本'not not null'。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM