Avatar of Computer Guy
Computer Guy
 asked on

MySQL Replace Syntax

Hi, I want to replace this ’ with ' in MySQL.

Table: songs
Field: name

This is what I have and It I get an error



SELECT REPLACE('name', '’', ''');

Any ideas?
MySQL ServerDatabases

Avatar of undefined
Last Comment
Ivo Stoykov

8/22/2022 - Mon
tigin44

SELECT REPLACE(name, '’', '''');
Ivo Stoykov

try

SELECT REPLACE('na’me', '’', "'"); // or
SELECT REPLACE("'name'", "'", "");

you also could escape characters SELECT REPLACE('na’me', '\’', "\'");

HTH

Ivo Stoykov
Computer Guy

ASKER
I need to put the table and field name in there too. So what is the syntax that way?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Ivo Stoykov

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Computer Guy

ASKER
When I use PHP my admin, I need to specify what table and field I want to change too. I can't use escape characters for what I'm trying to do.

So this: SELECT REPLACE(tablename.columnname, '’', "'");

Will replace all ’

with this '

?

Thanks
Ivo Stoykov

yes, but ' (single quote) is a string delimiter so you should escape it
SELECT REPLACE(tablename.columnname, '’', "\'");

Open in new window


so REPLACE will replace quotes only inside the data of the column, but not in column name

HTH

Ivo Stoykov