Replace All Occurrences using Oracle SQL regexp_replace 不区分大小写

Replace All Occurrences using Oracle SQL regexp_replace Case-insensitive

我愿意为所有出现的地方替换一个不区分大小写的字符串

给定的查询将所有吨替换为码。但是,它区分大小写。

SELECT regexp_replace(col_name, 'tons', 'yard') FROM DUAL;

我如何编写一个查询来替换所有匹配项,而不考虑字母大小写。我试过这个但没有用:

SELECT regexp_replace(col_name, 'tons', 'yard', 'i') FROM DUAL;

谢谢

使用 'i' 选项是正确的,但是您在它之前缺少两个参数。

REGEXP_REPLACE(<source_string>, <pattern>,<replace_string>, <position>, <occurrence>, <match_parameter>)

对于位置,使用1从头开始搜索。对于出现次数,使用 0 替换每次出现次数。

SELECT regexp_replace(col_name, 'tons', 'yard', 1, 0, 'i') FROM DUAL;

Examples

Official documentation