2012-01-26 18 views
5

Tengo una base de datos de información enviada desde un sitio web. Los datos de la columna principal se ha introducido el uso de rebajas, y contiene una gran cantidad de texto que se parece a esto:Uso de REEMPLAZAR con caracteres de escape en phpMyAdmin

Walgreens (www.walgreens.com) is the nation\\\'s largest drugstore chain. 

Estamos cambiar a un editor WYSIWYG diferente, y la necesidad de limpiar los datos. He intentado hacer esto en phpMyAdmin:

UPDATE sc_answer 
SET answer_text = REPLACE (answer_text, '\\\', '') 
WHERE sc_answer_id = 24806 

pero me da un error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''\\\', '') WHERE sc_answer_id = 24806' at line 3 

¿Puede alguien ayudarme? ¿Qué debo hacer para que esto funcione?

Respuesta

4

Para cada barra invertida \ en el campo de texto, utilice 2 barras diagonales inversas en el SQL. Por ejemplo, si la tabla es el siguiente:

mysql> select * from foo; 
+----+---------------------------------------------------------------------------+ 
| id | bar                  | 
+----+---------------------------------------------------------------------------+ 
| 1 | Walgreens (www.walgreens.com) is the nation\\\'s largest drugstore chain. | 
+----+---------------------------------------------------------------------------+ 
1 row in set (0.00 sec) 

continuación

mysql> update foo set bar = REPLACE(bar,'\\\\\\','') where id = 1; 
Query OK, 1 row affected (0.00 sec) 
Rows matched: 1 Changed: 1 Warnings: 0 

mysql> select * from foo; 
+----+------------------------------------------------------------------------+ 
| id | bar                 | 
+----+------------------------------------------------------------------------+ 
| 1 | Walgreens (www.walgreens.com) is the nation's largest drugstore chain. | 
+----+------------------------------------------------------------------------+ 
1 row in set (0.00 sec) 
+0

Gracias, que lo hizo! – EmmyS

Cuestiones relacionadas