Home » Interview Q & A » Q7. What is the difference between REPLACE() and STUFF() functions?

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

Our Categories

Blog Stats

  • 32,288 hits

Calendar

June 2013
M T W T F S S
« May    
 12
3456789
10111213141516
17181920212223
24252627282930

Please visit SQLVERSITY.COM for more details.

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: