CloudSeph
CloudSeph

Reputation: 883

how to perform mysql replace with " ' "?

UPDATE name SET name = REPLACE(student_name, 'a', ''');

By using the code above I want to update a to become '. How is that possible?

Upvotes: 1

Views: 186

Answers (2)

Rai Vu
Rai Vu

Reputation: 1635

There are several ways to include quote characters within a string:

“'” inside a string quoted with “'” may be written as “''”.

“"” inside a string quoted with “"” may be written as “""”.

Precede the quote character by an escape character (“\”).

“'” inside a string quoted with “"” needs no special treatment and need not be doubled or escaped. In the same way, “"” inside a string quoted with “'” needs no special treatment.

Upvotes: 0

Dekel
Dekel

Reputation: 62536

Escape the ' by using \':

UPDATE name SET name = REPLACE(student_name, 'a', '\'');

Or use double-quote:

UPDATE name SET name = REPLACE(student_name, 'a', "'");

Upvotes: 3

Related Questions