blob: 75b50211b488e3cfae44bfd23f6df59f217ac09f [file] [log] [blame] [view]
---
{
"title": "SUB_REPLACE",
"language": "en"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## sub_replace
### Description
#### Syntax
`VARCHAR sub_replace(VARCHAR str, VARCHAR new_str, INT start[, INT len])`
Return with new_str replaces the str with length and starting position from start.
When start and len are negative integers, return NULL.
and the default value of len is the length of new_str.
### example
```
mysql> select sub_replace("this is origin str","NEW-STR",1);
+-------------------------------------------------+
| sub_replace('this is origin str', 'NEW-STR', 1) |
+-------------------------------------------------+
| tNEW-STRorigin str |
+-------------------------------------------------+
mysql> select sub_replace("doris","***",1,2);
+-----------------------------------+
| sub_replace('doris', '***', 1, 2) |
+-----------------------------------+
| d***is |
+-----------------------------------+
```
### keywords
SUB_REPLACE