首页 > 数据库 > Oracle > translate与replace
Oracle/PLSQL: Replace Function
In Oracle/PLSQL, the replace function replaces a sequence of characters in a string with
another set of characters.
The syntax for the replace function is:
replace( string1, string_to_replace, [ replacement_string ] )
string1 is the string to replace a sequence of characters with another set of characters.
string_to_replace is the string that will be searched for in string1.
replacement_string is optional. All occurrences of string_to_replace will be replaced with
replacement_string in string1. If the replacement_string parameter is omitted,
the replace function simply removes all occurrences of string_to_replace, and returns the resulting string.
For example:
replace('123123tech', '123'); would return 'tech'
replace('123tech123', '123'); would return 'tech'
replace('222tech, '2', '3'); would return '333tech'
replace('0000123', '0'); would return '123'
replace('0000123', '0', ' '); would return ' 123'
Note: Translate and replace are very similar in their appearance but can produce very different results. Translate replaces by position, the first character of the list to match is replaced by the first character of the replacement list. The second character with the second, and if there are characters in the list to match that do not have positional equivalents in the replacements list they are dropped.
Replace replaces the string to match with the replacement string. The replacement of a single character is the same as that of TRANSLATE.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7659204/viewspace-897096/ ,如需转载,请注明出处,否则将追究法律责任。