[英]replace anything between a start string and end string (including special char) using REGEXP_REPLACE
update customer set cust_info= REGEXP_REPLACE(cust_info,'<start><cust_name><start><cust_name><this field has long string><end>','') where user_id=123;
ORA-12733: 正则表达式太长
所以我尝试了REGEXP_REPLACE(cust_info,'<start>[A-Z0-9_](*.?)<end>','');
但没有用。
我想将<start>
字符串和<end>
字符串之间的任何内容替换为空白。 (即删除<start>
和<end>
之间的任何内容)。
PS:- cust_info 列包含带有 html 标签的长字符串。
你的正则表达式似乎不行试试表达式<start>(.)*?<end>
WITH da AS (
SELECT '<start><cust_name><start><cust_name><this field has long string><end>' AS cust_info FROM dual UNION ALL
SELECT 'name_test' AS cust_info FROM dual
) SELECT REGEXP_REPLACE(cust_info,'<start>(.)*?<end>','') FROM da;
尝试
UPDATE
customer
SET
cust_info = REGEXP_REPLACE(cust_info, '<start>(.)*?<end>', '')
WHERE
user_id = 123;
解释:-
<start> //Matches literal <start>
(.) //Matches any character except linebreaks
* //Matches 0 or more of the preceding token of (.)
? //Makes the preceding quantifier lazy, causing it to match as few characters as possible
<end> //Matches literal <end>
如果您的字符串有换行符,请使用 match_parameter 将其考虑在内
REGEXP_REPLACE ( cust_info, '<start>(.*?)*?<end>' , '' , 1 , 1 , 'n' )
基于:
REGEXP_REPLACE ( source_string, search_pattern
[, replacement_string
[, star_position
[, nth_occurrence
[, match_parameter ]
]
]
]
)
所以:
UPDATE
customer
SET
cust_info = REGEXP_REPLACE ( ID_DESC, '<start>(.*?)*?<end>' , '' , 1 , 1 , 'n' )
WHERE
user_id = 123;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.