PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Editing fields in bulk
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Editing fields in bulk

Réponse
 
LinkBack Outils de la discussion
Vieux 05/09/2007, 02h41   #1
Brian Dunning
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Editing fields in bulk

I have a column where I need to replace all instances of the text "US-
Complete" (contained within a long sentence) with "US Complete".
There are probably 50 or 100 of them. I'm really scared to do it
since I can't risk screwing up that column - what's the correct syntax?
  Réponse avec citation
Vieux 05/09/2007, 03h14   #2
Hartleigh Burton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Editing fields in bulk

I could use the same thing... just looking through the documentation there
is a replace() function. Maybe do a backup/restore to a test database before
doing this on your live system...

UPDATE `tablename` SET `fieldname`=REPLACE(tablename.fieldname,'US-
Complete','US Complete') WHERE `fieldname` LIKE '%US- Complete%';





-----Original Message-----
From: Brian Dunning [mailto:brian@briandunning.com]
Sent: Wednesday, 5 September 2007 10:42 AM
To: mysql@lists.mysql.com
Subject: Editing fields in bulk

I have a column where I need to replace all instances of the text "US-
Complete" (contained within a long sentence) with "US Complete".
There are probably 50 or 100 of them. I'm really scared to do it
since I can't risk screwing up that column - what's the correct syntax?

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=h...ertainment.com


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.485 / Virus Database: 269.13.5/989 - Release Date: 4/09/2007
5:54 PM


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.485 / Virus Database: 269.13.5/989 - Release Date: 4/09/2007
5:54 PM


  Réponse avec citation
Vieux 05/09/2007, 03h30   #3
Baron Schwartz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Editing fields in bulk

Brian Dunning wrote:
> I have a column where I need to replace all instances of the text
> "US-Complete" (contained within a long sentence) with "US Complete".
> There are probably 50 or 100 of them. I'm really scared to do it since I
> can't risk screwing up that column - what's the correct syntax?


UPDATE tbl SET col=REPLACE(col, 'US-Complete', 'US Complete');

If there are spaces in front and back, perhaps you should add some extra
insurance to avoid changing 'US-Completely' or 'BUS-Complete' as well:

UPDATE tbl SET col=REPLACE(col, ' US-Complete ', ' US Complete ');

The best insurance is to do a SELECT first to see what will be changed:

SELECT col, REPLACE(col, 'US-Complete', 'US Complete') FROM tbl;

Baron
  Réponse avec citation
Vieux 05/09/2007, 03h44   #4
Gary Josack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Editing fields in bulk

Brian Dunning wrote:
> I have a column where I need to replace all instances of the text
> "US-Complete" (contained within a long sentence) with "US Complete".
> There are probably 50 or 100 of them. I'm really scared to do it since
> I can't risk screwing up that column - what's the correct syntax?
>
> --MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=lists@byoteki.com
>

mysql> select * from replacetest;
+----+--------------------------------+
| id | reptest |
+----+--------------------------------+
| 1 | this is a test US-Complete wii |
| 2 | look US-Complete is here |
| 3 | Fun test |
+----+--------------------------------+
3 rows in set (0.00 sec)

mysql> update replacetest set reptest=replace(reptest, 'US-Complete',
'US Complete') where reptest like '%US-Complete%';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> select * from replacetest;
+----+--------------------------------+
| id | reptest |
+----+--------------------------------+
| 1 | this is a test US Complete wii |
| 2 | look US Complete is here |
| 3 | Fun test |
+----+--------------------------------+
3 rows in set (0.00 sec)

  Réponse avec citation
Vieux 05/09/2007, 13h02   #5
Martijn Tonies
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Editing fields in bulk



> I have a column where I need to replace all instances of the text "US-
> Complete" (contained within a long sentence) with "US Complete".
> There are probably 50 or 100 of them. I'm really scared to do it
> since I can't risk screwing up that column - what's the correct syntax?


When you screw up, that's when you do a "rollback". Welcome to
transactions.

Martijn Tonies
Database Workbench - development tool for MySQL, and more!
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h08.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11609 seconds with 13 queries