User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 6 May 2005, 08:24   #1
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
str_replace in MySQL?

Hola, not been on here for ages... but I knew where to turn for geeky assistance!

I'm no good with MySQL. Is there a way I can make it search for a particular character, and replace it with another? Or do I have to write a script (PHP I guess) to do it?

Cheers!

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 6 May 2005, 09:06   #2
meglamaniac
Born Sinful
 
meglamaniac's Avatar
 
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: str_replace in MySQL?

afaik you'll have to do it in a secondary language, like PHP as you suggested.
My knowledge of SQL is far from extensive so I may be corrected.

__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
meglamaniac is offline   Reply With Quote
Unread 6 May 2005, 10:33   #3
Dante Hicks
Clerk
 
Join Date: Jun 2001
Posts: 13,940
Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: str_replace in MySQL?

http://dev.mysql.com/doc/mysql/en/string-functions.html

Try there.

Would :

Quote:
REPLACE(str,from_str,to_str)

Returns the string str with all occurrences of the string from_str replaced by the string to_str.


mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.com'
Be useful, in some sort of sub-query context?
Dante Hicks is offline   Reply With Quote
Unread 10 May 2005, 00:02   #4
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: str_replace in MySQL?

Cheers - shoulda readTFM

I'm gonna try it on a copy of the DB first!
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 25 May 2005, 01:41   #5
Karhig
Registered User
 
Join Date: May 2005
Posts: 2
Karhig is an unknown quantity at this point
Re: str_replace in MySQL?

Quote:
Originally Posted by Dante Hicks
http://dev.mysql.com/doc/mysql/en/string-functions.html

Try there.

Would :


Be useful, in some sort of sub-query context?
I don't know for certain, but I suspect that that wouldn't work. The description of REPLACE states that it replaces one string with another only when outputting the query result to the outside world. It sounded as though the threa poster wanted to actually alter the values stored in the database itself. REPLACE would not do this. It might fool you since everytime you queried the database it would return what you expect so long as you left the REPLACE in there, but if you removed the REPLACE it would return to what was originally in the database. If this is all you need the go for it, if you are trying to actually alter what is stored in the database then you will probably need to write a script that alters each row in the database. Shouldn't be too difficult, a couple of lines of code at best.
Karhig is offline   Reply With Quote
Unread 25 May 2005, 12:48   #6
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Re: str_replace in MySQL?

Quote:
Originally Posted by Karhig
I don't know for certain, but I suspect that that wouldn't work. The description of REPLACE states that it replaces one string with another only when outputting the query result to the outside world. It sounded as though the threa poster wanted to actually alter the values stored in the database itself. REPLACE would not do this. It might fool you since everytime you queried the database it would return what you expect so long as you left the REPLACE in there, but if you removed the REPLACE it would return to what was originally in the database. If this is all you need the go for it, if you are trying to actually alter what is stored in the database then you will probably need to write a script that alters each row in the database. Shouldn't be too difficult, a couple of lines of code at best.
An UPDATE would do it, which (once you knew about REPLACE) would be obvious to anyone who knew some SQL.
__________________
#linux
queball is offline   Reply With Quote
Unread 29 Apr 2007, 14:44   #7
dageek
Guest
 
Posts: n/a
Re: str_replace in MySQL?

Just to say the query your looking for works like this:

UPDATE table SET field=REPLACE(table.field, ' ','') WHERE 1;

This would for example remove the spaces from the field.
  Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 13:15.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018