Updated on 2026-11-06 GMT+08:00

replace

Replaces all occurrences of the old string in the str string with the new string and returns the replaced string. If no overlapping string is found, the original str is returned.

Syntax

replace(string <str>, string <old>, string <new>) 

Parameters

Parameter

Mandatory

Type

Description

str

Yes

STRING

The string to be replaced.

old

Yes

STRING

The string to be compared.

new

Yes

STRING

The replacement string.

Return Values

Returns a value of type STRING.

If any input parameter is NULL, NULL is returned.

Example Code

Returns AA123AA.

SELECT replace('abc123abc', 'abc', 'AA'); 

Returns NULL.

SELECT replace('abc123abc', null, 'AA');