REPLACE is a string manipulation function that manipulates all string data types (BIT, BLOB, and CHARACTER), and replaces parts of a string with supplied substrings.
REPLACE returns a string consisting of the source string, with each occurrence of the search string replaced by the replace string. The parameter strings can be of the CHARACTER, BLOB, or BIT data types, but all three must be of the same type.
If any parameter is NULL, the result is NULL.
REPLACE('ABCDABCDABCDA', 'A', 'AA') -- RESULT = AABCDAABCDAABCDAA REPLACE('AAAABCDEFGHAAAABCDEFGH', 'AA', 'XYZ') -- RESULT = XYZXYZBCDEFGHXYZXYZBCDEFGH REPLACE('AAAAABCDEFGHAAAABCDEFGH', 'AA', 'XYZ') -- RESULT = XYZXYZABCDEFGHXYZXYZBCDEFGH
The first example shows that replacement is single pass. Each occurrence of A is replaced by AA but these are not then expanded further.
The second example shows that characters once matched are not considered further. The first AA pair is matched, replaced and disregarded. The second and third As are not matched.
The third example shows that matching is from the left. The first four As are matched as two pairs and replaced. The fifth A is not matched.
If you do not specify the replace string expression, the replace string defaults to an empty string and the behavior of the function is to delete all occurrences of the search string from the result.
Notices |
Trademarks |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
ak05241_ |