Replace string query - double trouble!

This is a discussion on Replace string query - double trouble! within the MySQL Database forums, part of the Database Forums category; UPDATE `tableName` SET `fieldName` = REPLACE(fieldName,"stringOne","stringTwo") I use the above code to strip strings ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-24-2005
Gary@garywhittle.co.uk
 
Posts: n/a
Default Replace string query - double trouble!

UPDATE `tableName` SET `fieldName` =
REPLACE(fieldName,"stringOne","stringTwo")

I use the above code to strip strings from my table, and most of the time
this works well. However, I have several fields with double quotes within,
and I would like to remove all double quotes.

Doing this does not work, and generates an error:

UPDATE `tableName` SET `fieldName` = REPLACE(fieldName,""","")

Can anyone point me in the right direction?

Regards,

Gary.


Reply With Quote
  #2 (permalink)  
Old 11-24-2005
Giuseppe Maxia
 
Posts: n/a
Default Re: Replace string query - double trouble!

Gary@garywhittle.co.uk wrote:
> UPDATE `tableName` SET `fieldName` =
> REPLACE(fieldName,"stringOne","stringTwo")
>
> I use the above code to strip strings from my table, and most of the time
> this works well. However, I have several fields with double quotes within,
> and I would like to remove all double quotes.
>
> Doing this does not work, and generates an error:
>
> UPDATE `tableName` SET `fieldName` = REPLACE(fieldName,""","")
>
> Can anyone point me in the right direction?
>
> Regards,
>
> Gary.
>
>


You need one more double quote to escape it:
UPDATE `tableName` SET `fieldName` = REPLACE(fieldName,"""","")

or you can use single quotes to quote a double quote:
UPDATE `tableName` SET `fieldName` = REPLACE(fieldName,'"',"")

ciao
gmax

--
_ _ _ _
(_|| | |(_|><
_|
http://gmax.oltrelinux.com
Reply With Quote
  #3 (permalink)  
Old 11-24-2005
Kai Ruhnau
 
Posts: n/a
Default Re: Replace string query - double trouble!

Giuseppe Maxia wrote:

[replace double quotes in strings]
>
> You need one more double quote to escape it:
> UPDATE `tableName` SET `fieldName` = REPLACE(fieldName,"""","")


Additionaly it is worth noting, that using double quotes as string
delimiter is an extension of MySQL. The SQL standard uses double quotes
for identifiers. MySQL can be configured in both ways, thus using double
quotes can cause one or the other behavior.

The best practice should be to always use single quotes for strings.

UPDATE `tableName` SET `fieldName` = REPLACE(`fieldName`,'"','')

Greetings
Kai

--
This signature is left as an exercise for the reader.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:32 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0