regexp_replace
regexp_replace is a function in SQL that allows you to replace a pattern in a string with a new pattern. The function takes three arguments:
-
The input string: This is the string that you want to replace the pattern in.
-
The pattern: This is a regular expression that defines the pattern you want to replace.
-
The replacement: This is the new pattern that you want to replace the old pattern with.
For example, the following query replaces all occurrences of the word "apple" with "orange" in the input string:
SELECT regexp_replace('I like apples, apples are my favorite fruit', 'apple', 'orange');
The output of this query is:
I like oranges, oranges are my favorite fruit
Note that the regular expression used in the pattern argument can be as simple or as complex as needed to match the desired pattern.
原文地址: http://www.cveoy.top/t/topic/en1 著作权归作者所有。请勿转载和采集!