Remove \(backslash) with "" in database field using update command in SQL - mysql

When I run this sql command:
UPDATE chat_data
SET message = replace(message, '\', '')
LIMIT 1 ;
It gives me syntax error:
13:07:46 UPDATE chat_data SET message = replace(message, '\', '')
LIMIT 1 ; Error Code: 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 ''\', '') LIMIT 1' at line 1 0.237 sec
Any solution for this ?

You need to escape the \ character:
UPDATE chat_data SET message = replace(message, '\\', '') LIMIT 1 ;

I had a case today on a legacy project.
Here is a solution for a SELECT statement :
'SELECT * FROM my_table WHERE label = REPLACE("'.mysql_real_escape_string($label).'", "'.mysql_real_escape_string('\\').'", "")'

If you want to replace visible backslash (\) with sql you could also use
REPLACE(message, CHAR(92), '')

Related

#1064 syntax mysql error with " symbol

I need to remove all " symbols in name column
UPDATE oc_product_description SET name = REPLACE(name, """, "");
When I try to simulate this query I get this syntax 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 '"&quot)' at line 1
It works fine here:
CREATE TABLE oc_product_description (
`name` varchar(50)
) ;
INSERT INTO oc_product_description values
('some random text "'),
('some text "'),
('some text');
UPDATE oc_product_description SET name = REPLACE(name, '"', '');
Demo
UPDATE oc_product_description SET
name = REPLACE(name, '"', '');

How to update table set column = null where column = '\' without error of MySQL server version for the right syntax to use near ''\'' at line 1

How to update table set column = null where column = \ in mysql?
I always got error of 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 ''\'' at line 1
You should use '\\'
update students set firstname = null where firstname = '\\'

Syntax error on update SQL statement

I'm getting a syntax error when I want to use md5 over url column. Not sure what's wrong with it:
update table {$GLOBALS['tables']['tableame']} set urlhash = md5(url)
Error message:
Database error 1064 while doing query 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 'table tablename set urlhash = md5(url)' at line 1
Try passing md5 in single quotes as that is a string
update {$GLOBALS['tables']['tableame']} set urlhash = 'MD5_URL_HERE'
following is the syntax
UPDATE table_name SET column_name = `new_value' [WHERE condition];

Error 1064:You have an error in your SQL syntax

I want run this query but get an error:
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 'UPDATE `ads` SET `aDesc` = replace(aDesc, 'amp;', '')' at line 3
My query is:
UPDATE `ads`
SET `aName` = replace(aName, 'amp;', '')
UPDATE `ads`
SET `aDesc` = replace(aDesc, 'amp;', '');
What's the problem?
Your query looks like two queries without a separating delimiter.
The more efficient option is to do both changes in one query:
UPDATE ads
SET aName = replace(aName, 'amp;', ''),
aDesc = replace(aDesc, 'amp;', '');
but if you must run two queries:
UPDATE ads SET aName = replace(aName, 'amp;', '');
UPDATE ads SET aDesc = replace(aDesc, 'amp;', '');

Error in my stored-procedure

i have an error in my stored-procedure. I use MySql DB
SET #counter = 1;
SET #last = 0;
UPDATE Customer SET ordre = (IF(#last = customer_id,#counter + 1,#counter = 1)),
#last = customer_id
My Error
Script line: 3 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 '#last = customer_id ORDER BY
customer_id' at line 2
You cannot set variables in SET clause of UPDATE statement. '#last = customer_id' causes the error.
From the reference -
UPDATE syntax - '...SET col_name1=expr1 [, col_name2=expr2 ...]'
The SET clause indicates which columns to modify and the values they should be given.