RSS Feed

SQL Replace

SQL Replace

Replaces all occurrences of a specified string value with another string value.

Replace(string_1, string_2, string_3): In string_1, find exactly where string_2 occurs, and replace it with string_3.

SQL Replace can also be used to delete the occurrences of a substring.

Syntax

REPLACE ( string_expression , string_pattern , string_replacement )

SQL REPLACE - Example 1

The following example replaces the string cde in abcdefghicde with xxx.

SELECT REPLACE('abcdefghicde','cde','xxx');
GO

Here is the result set.

------------
abxxxfghixxx
(1 row(s) affected)

[Source of Example 1]

SQL REPLACE - Example 2

Select Replace ('The sea is blue.', 'blue','green') From dual;

REPLACE('THESEA
---------------
The sea is green.

No comments:

Post a Comment