

# REPLACE function
<a name="REPLACE"></a>

Replaces all occurrences of a set of characters within an existing string with other specified characters. 

REPLACE is similar to the [TRANSLATE function](TRANSLATE.md) and the [REGEXP\$1REPLACE function](REGEXP_REPLACE.md), except that TRANSLATE makes multiple single-character substitutions and REGEXP\$1REPLACE lets you search a string for a regular expression pattern, while REPLACE substitutes one entire string with another string.

## Syntax
<a name="REPLACE-synopsis"></a>

```
REPLACE(string1, old_chars, new_chars)
```

## Arguments
<a name="REPLACE-arguments"></a>

 *string*   
CHAR or VARCHAR string to be searched search 

 *old\$1chars*   
CHAR or VARCHAR string to replace. 

 *new\$1chars*   
New CHAR or VARCHAR string replacing the *old\$1string*. 

## Return type
<a name="REPLACE-return-type"></a>

VARCHAR

If either *old\$1chars* or *new\$1chars* is NULL, the return is NULL. 

## Examples
<a name="REPLACE-examples"></a>

The following example converts the string `Shows` to `Theatre` in the CATGROUP field: 

```
select catid, catgroup,
replace(catgroup, 'Shows', 'Theatre')
from category
order by 1,2,3;

 catid | catgroup | replace
-------+----------+----------
     1 | Sports   | Sports
     2 | Sports   | Sports
     3 | Sports   | Sports
     4 | Sports   | Sports
     5 | Sports   | Sports
     6 | Shows    | Theatre
     7 | Shows    | Theatre
     8 | Shows    | Theatre
     9 | Concerts | Concerts
    10 | Concerts | Concerts
    11 | Concerts | Concerts
(11 rows)
```