SQLite: replace Function
This SQLite tutorial explains how to use the SQLite replace function with syntax and examples.
Description
The SQLite replace function replaces all occurrences of a specified string.
Syntax
The syntax for the replace function in SQLite is:
replace( string, from_substring, to_substring )
Parameters or Arguments
- string
- The source string.
- from_substring
- The substring to find. All occurrences of from_substring found within string are replaced with to_substring.
- to_substring
- The replacement substring. All occurrences of from_substring found within string are replaced with to_substring.
Note
- The replace function performs a case-sensitive replacement.
Applies To
The replace function can be used in the following versions of SQLite:
- SQLite 3.8.6, SQLite 3.8.x, SQLite 3.7.x, SQLite 3.6.x
Example
Let's look at some SQLite replace function examples and explore how to use the replace function in SQLite.
For example:
sqlite> SELECT replace('techonthenet.com', 'techonthenet', 'checkyourmath'); Result: 'checkyourmath.com' sqlite> SELECT replace('TechOnTheNet.com', 'techonthenet', 'checkyourmath'); Result: 'TechOnTheNet.com' sqlite> SELECT replace('abc abc', 'a', 'B'); Result: 'Bbc Bbc' sqlite> SELECT replace('abc abc', 'A', 'B'); Result: 'abc abc' sqlite> SELECT replace('789 789', 9, 3); Result: '783 783'
Advertisements