What is the difference between REPLACE() and STUFF() functions?

REPLACE()

It is used to replace all the occurrences of the second argument in the first argument with the third argument.

Syntax:

REPLACE (String, StringPattern, StringTobeReplaced)

Ex:

SELECT REPLACE (‘SQLVERSITY is a good website’, ‘good’, ‘great’)

Output:

SQLVERSITY is a great website

STUFF()

It is used to overwrite the specified length of string with the new string.

Syntax:

STUFF (String_expression, start_position, length, Replace_string)

Ex:

SELECT STUFF (‘I am a bad boy’,8 ,3 ,‘good’)

Output:

I am a good boy

Leave a Reply

Your email address will not be published. Required fields are marked *