#1064 syntax mysql error with " symbol - mysql

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, '"', '');

Related

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 = '\\'

MARIADB : Insert and Update table based on data from another table

/* Here is the code i used to merge but i get error and am unable update
Error : SQL Error [1064][42000] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the righr syntax to use near 'Merge temp2 as t' at line 1
*/
BEGIN
MERGE temp2 as t
using temp1 as s ON (t.slno = s.slno)
-- Insert values when data no present
WHEN NOT MATCHED THEN INSERT VALUES
(s.slno,s.name,s.address);
-- Update when values present
WHEN MATCHED then UPDATE SET
t.slno = s.slno,
t.name = s.name,
t.address = s.address;
END
You could probably use this:
INSERT INTO temp2 (slno, name, address) SELECT slno, name, address FROM temp1
ON DUPLICATE KEY UPDATE
slno = VALUES(slno), name = VALUES(name), address = VALUES(address)

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;', '');

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

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), '')

Conditional update/insert in MySQL

I found here a topic about an MySQL IF, ELSE query,i adapted it but i can't figure it out what is the problem with it.
Here is the query:
IF (SELECT * FROM `jos_import03_07_2011` WHERE `cod_oem` = 'OP-4CL') IS NULL THEN
INSERT INTO `jos_import03_07_2011` (`tip_imp`, `tip_produs`, `producator`,
`cod_intern`, `desc`, `cod_oem`, `pret`, `valuta`) VALUES ('Imprimanta Laser',
'Piese Schimb', 'BROTHER', 'BR-200503', '', 'OP-4CL', '338.49', 'EUR');
ELSE UPDATE `jos_import03_07_2011` SET `pret` = '338.49' WHERE `cod_oem` = 'OP-4CL';
END IF;
And here is the error:
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 'IF (SELECT * FROM
`jos_import03_07_2011` WHERE `cod_oem` = 'OP-4CL') IS NULL THE' at line 1
This is the original post:
Conditional mySQL statement. If true UPDATE, if false INSERT
Thanks,
Sebastian
UPDATE
Error code for IF EXISTS:
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 'IF EXISTS (SELECT * FROM
`jos_import03_07_2011` WHERE `cod_oem` = 'OP-4CL') THEN' at line 1
Any reason you can't use the INSERT ... ON DUPLICATE KEY syntax?
INSERT INTO `jos_import03_07_2011` (`tip_imp`, `tip_produs`, `producator`,
`cod_intern`, `desc`, `cod_oem`, `pret`, `valuta`)
VALUES ('Imprimanta Laser', Piese Schimb', 'BROTHER', 'BR-200503', '', 'OP-4CL', '338.49', 'EUR')
ON DUPLICATE KEY UPDATE SET pret = VALUES(pret)
would be far more efficient: one less query and far less code to debug.