Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace function in SQL

I have a sample text that contains '-' or ' '. So I want a sql replace statement that replaces both '-' and ' ' with ''.

My query is:

SELECT REPLACE('SQL-Tu torial','-',' ','');

Desired outcome:

SQLTutorial

Error: I get error for Replace function arguments.

The replace function requires 3 argument(s).

Any help?

like image 973
Rick Avatar asked Oct 27 '25 13:10

Rick


2 Answers

You can't use 3 parameters in a REPLACE function. Instead you can use it twice just like below :

SELECT REPLACE(REPLACE('SQL-Tu torial', '-', ''), ' ', '');

Output :

SQLTutorial
like image 129
Md. Suman Kabir Avatar answered Oct 30 '25 04:10

Md. Suman Kabir


Nest two REPLACE functions.

REPLACE(REPLACE())
like image 42
Tab Alleman Avatar answered Oct 30 '25 04:10

Tab Alleman