REPLACE
All functions > STRING > REPLACE
Returns the string with all occurrences of a substring replaced with another substring.
Signatures
Returns: String with all occurrences replaced
REPLACE(string: VARCHAR, search: VARCHAR, [replacement: VARCHAR]) → VARCHAR sql
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | String to search in |
search | VARCHAR | Yes | Substring to find |
replacement | VARCHAR | No | String to replace with (optional, defaults to empty string) |
Notes
- Replaces ALL occurrences, not just the first
- Case-sensitive search
- If replacement is omitted, removes the search string
- If search string is not found, returns original string unchanged
Examples
FeatureQL
SELECT
f1 := REPLACE('Hello World', 'o', 'X'), -- Replace all 'o' with 'X'
f2 := REPLACE('foo bar foo', 'foo', 'baz'), -- Replace all occurrences
f3 := REPLACE('foo-bar-baz', '-', '_'), -- Replace dashes with underscores
f4 := REPLACE('foo-bar-baz', '-'), -- Remove dashes (omit replacement)
f5 := REPLACE('ABCABC', 'ABC', 'X'), -- Multiple replacements
f6 := REPLACE('Hello', 'xyz', 'abc') -- No match, no change
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR | f6 VARCHAR |
|---|---|---|---|---|---|
| HellX WXrld | baz bar baz | foo_bar_baz | foobarbaz | XX | Hello |
On this page