Replace

MySQL, PostgreSQL, SQLite
Post Reply
Anonymous
 

Replace

Post by Anonymous »

Hi,

wie kann ich in einer Tabelle in einer bestimmten Zeile eine buchstabenfolge durch eine andere ersetzen? Gibt es da nen befehl für? Ich hab schon gegoogelt, aber nix gefunden.

Daniel
jtb
Posts: 599
Joined: 2002-08-18 16:41
Location: Darmstadt
Contact:
 

Re: Replace

Post by jtb »

Wie wäre es mit Update und replace?

siehe http://www.mysql.com/doc/en/String_functions.html
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'
btw: in Datenbanken solltest du nicht in Zeilen denken, sondern mit Mengen..
Anonymous
 

Re: Replace

Post by Anonymous »

Hmm, gute Sreite, aber ich bin zu dumm. Was mache ich denn hier falsch:

SELECT REPLACE('alt', 'alt', 'neu');

Daniel
jtb
Posts: 599
Joined: 2002-08-18 16:41
Location: Darmstadt
Contact:
 

Re: Replace

Post by jtb »

funktioniert doch..

Jetzt nur noch daraus ein Update machen..
Anonymous
 

Re: Replace

Post by Anonymous »

Hä? Update? Au man, ich hab doch kein Plan von MySQL. Wie lautet denn die komplette syntax für mein Problem???

Daniel
jtb
Posts: 599
Joined: 2002-08-18 16:41
Location: Darmstadt
Contact:
 

Re: Replace

Post by jtb »

mmh, dann solltest du dich schnellstens mal darüber informieren..

Code: Select all

Update tabelle set text = REPLACE( text, "alt", "neu" ) where PKID = '1';
sollte dir einen guten Ansatz geben (nicht getestet)
olaf.dietsche
Posts: 401
Joined: 2002-12-19 02:06
Location: Siegburg
 

Re: Replace

Post by olaf.dietsche »

DMKlein wrote:Hä? Update? Au man, ich hab doch kein Plan von MySQL.
Das ist kein MySQL spezifisches Problem. Du solltest dich ein bischen in SQL einarbeiten. SQL ist in ihren Grundzügen eine recht einfache Sprache.

Hier sind einige Einführungen bzw. Referenzen zu SQL:
http://dx1.hrz.uni-dortmund.de:8001/doc ... racle.html
http://www.usegroup.de/software/phptuto ... erenz.html
http://www.carano.de/SQLHelp/defaultsql2.html

Und hier gibt's das ganze natürlich auch für MySQL:
http://www.mysql.com/doc/de/index.html
Das ist allerdings etwas umfangreicher.
Post Reply