Jump to content

using mysql replace() to replace quotes??


john_6767

Recommended Posts

ok, so i am tidying a databse up and need to replace all the " with Inch and all the ' with foot (in the data..)

the following sql code doesn't work when using quotes and doubles quotes, it must think they're syntax??

update TABLE set COLUMN = replace(COLUMN, OLD_VALUE, NEW_VALUE);

any ideas, i'm new to sql, maybe theres something i can put around the " saying that they are a string?
Link to comment
https://forums.phpfreaks.com/topic/18860-using-mysql-replace-to-replace-quotes/
Share on other sites

Can you elaborate more? If your question is as simple as I think, then knowing that \ will force anything directly after it to be interpretted literally in a database will probably help you out (Except for predefined escape sequences).

INSERT INTO table VALUES('This is a \" test');
Inserts: This is a " test

Edit:

Looking at your post a little bit, I might understand your problem better.

UPDATE table SET column = replace(column, '\"', 'feet');
Does that sound plausible?

that sounds like what i thought i was after, although after more thought and looking at your first comment i may not need to update the database.

It seems like better practise to leave the database as standard data and then add/remove as needed the slashes by using php code.

Thanks for the tip though in putting the backslash before the " in the replace function.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.