SQLite Replace() Function

  Total Views : 634
  Comments : 0
  Keywords : SQLite replace function to replace multiple occurrences of string with example, Replace particular part of string using sqlite replace() function

Here we will learn Replace() function in SQLite and how to use SQLite Replace() function to insert or replace defined string value with examples.

SQLite Replace() Function

In SQLite Replace() function is used to find and replace the particular part of string or all occurrences of  a specified string.

 

The SQLite Replace() function will perform a case-sensitive replacement for the specified string.

Syntax of SQLite Replace() Function

Following is the syntax of SQLite Replace() function to find and replace particular part of string.

 

replace( string, find_string, replace_string )

In above SQLite replace() function syntax we defined few parameters those are

 

string – Its source string which is used to find and replace the string.

 

find_string – Its substring which we use to search for the ocurrences in given string to replace with replace_string.

 

replace_string – Its replacement string which we used to replace all occurrences of find_string in main string.

 

Now we will see how to use SQLite Replace() function to return number of characters in string with examples.

SQLite Replace() Function Examples

Following are the simple examples of SQLite Length() function to find and replace all occurrences of specified string.

 

sqliteSELECT replace('aspdotnet-suresh','aspdotnet','Tutlane');

 

replace("aspdotnet-suresh")

-----------------------------

Tutlane-suresh

 

sqliteSELECT replace('Aspdotnet-suresh','aspdotnet','Tutlane');

 

replace("Aspdotnet-suresh")

-----------------------------

Aspdotnet-suresh

 

sqliteSELECT replace('ABC','abc','XYZ');

 

replace("ABC")

-----------------------------

ABC

 

sqliteSELECT replace('Tutlane','Tut','');

 

replace("Tutlane")

-----------------------------

lane

SQLite Replace() Function with Tables

Now we will see how to use SQLite Replace() function with tables for that create one tabled called “test” and insert data like as shown following.

 

sqliteCREATE TABLE test(i TEXT);

 

sqliteSELECT from test;

 

i

----------

Shweta

Shwets

Shwati

Vinay

Vijay

Vivek

Now we will replace the charachters “Shw” with “H” where column i starts with “Shw” like as shown following.

 

sqliteSELECT replace(i,'Shw','H'FROM test WHERE i LIKE 'Shw%';

 

replace(i,"Shw","H")

--------------------

Heta

Hets

Hati

This is how we can use SQLite Replace() function to replace particular part of specified string based on our requirements.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User