Purpose
This function replaces substrings in the char1 string that match char2 with char3.
Syntax
REPLACE(char1,char2[,char3])
Parameters
Parameter |
Description |
|---|---|
| char1 | The string to be replaced. The data type can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB. |
| char2 | The string to be replaced. The data type can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB. |
| char3 | The replacement string. The default value is an empty string, which indicates that the matched substrings are to be removed. The data type can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB. Note If char3 is not specified or is NULL, all occurrences of char2 in char1 are removed. If char2 is an empty string, the result is char1. |
Return type
The returned string has the same character set as char1.
If
char1is of theLOBdata type, the function returns a value of theCLOBdata type.If
char1is not of theLOBdata type, the function returns a value of theVARCHAR2data type.
Examples
Replace the b character in the Oceanbase string with B.
obclient> SELECT REPLACE('Oceanbase','b','B') "replace" FROM DUAL;
+-----------+
| replace |
+-----------+
| OceanBase |
+-----------+
1 row in set
