Sqlite Replace Function

SQLite: replace Function

This SQLite post 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('AODBA.com', 'AODBA', 'checkyoursite');
Output:  'checkyoursite.com'


sqlite> SELECT replace('abc abc', 'a', 'B');
Output:  'Bbc Bbc'

sqlite> SELECT replace('abc abc', 'A', 'B');
Output:  'abc abc'

sqlite> SELECT replace('789 789', 9, 3);
Output:  '783 783'