SQL Replace spaces with underscore - mysql

I am trying to run an SQL Query to replace the spaces in my filenames with an underscore:
UPDATE oc_product_image set image=replace(image,' ', '_');
I found this sql query here: Remove space and replace with _ in phpMyAdmin
I am running it in the SQL tab in phpMyAdmin
When I simulate it I get this 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 '' ''_') FROM oc_product_image WHERE' at line 1
What am I doing wrong?

Underscore is a special character in SQL. Try escaping it with a backslash and see if that helps.

Related

MySQL replace QUOTE

I need to replace &quote; in a string. I tried to do this:
SET `title` = REPLACE( `title`, '"', '' )
but it gives me a parsing error.
This is the 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
Server version: 5.5.57-cll - MySQL Community Server (GPL)
How do I do this?
Your query should work, but it seems like the error is from another query. Anyhow:
Try this:
UPDATE tbl_name
SET
field_name = REPLACE(field_name,
string_to_find,
string_to_replace)
WHERE
conditions;
Example:
UPDATE bbb_sefurls
SET
metatitle = REPLACE(metatitle,
'&quote;',
'');
No need for a condition
This is simple approach but it replaces all the " in string.
UPDATE dummy_tab SET metatitle =REPLACE(metatitle,'/"','') WHERE metatitle LIKE '%"'
If I'm to read your error 100% as written... you have the word quote spelled wrong some where.
...for the right syntax to use near ''&quot)'
notice in your error it shows no "e" There for your replace statement would also NOT catch this.
Or more closely looking at the image you posted... you are replacing
&quote(semicolon)
with
''
But the error says it is finding the string
&quote)
somewhere in your query... Which would seem to be invalid.
Search your code for
&quot)

How to replace apostrophe in database via sql

I am trying to replace "?t" string to "'t" (apostrophe t)
I enter this command in phpMyAdmin
UPDATE "myTable"
SET "myColumn" = REPLACE ("myColumn", "\?t", "\'t")
as suggested in How can I use mySQL replace() to replace strings in multiple records?)
I get this 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 #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 "myTable"
SET "myColumn" = REPLACE ("myColumn", "\?t", "\'t") at line 1
What is wrong with my command?
Thanks
Don't quote table or column names. If you need to escape them use backticks
UPDATE `myTable`
SET `myColumn` = REPLACE (`myColumn`, '?t', '\'t')

Error while updating inMySQL

I am working with MySQL and I am facing issues while updating the below command:
UPDATE group_access_mst SET
access='0',view='0',add='0',modify='0',delete='0',save='0',xl='0',import='0' WHERE role_id='1' AND page_id='1';
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 'add='0',modify='0',delete='0',save='0',xl='0',import='0' WHERE
role_id='1' AND p' at line 1
If I remove add,delete from the quesry it works fine!!
Is there any way i can make these command to work. I can understand that in MySQL ADD,DELETE,SELECT,INSERT are commands so it is not working.
In this case i need to change the fields names?
You should enclose the field names within back quote:
UPDATE group_access_mst
SET `access`='0',
`view`='0',
`add`='0',
`modify`='0',
`delete`='0',
`save`='0',
`xl`='0',
`import`='0'
WHERE role_id='1'
AND page_id='1';

Mysql search and replace when involving "http://"

I'm trying to search and replace in MYSQL but get an error. I'm quessing it's because of the "http://"
Anyone got any suggestions when trying replace this type of thing?
Code entered:
update movies_news set select_page = replace(select_page, ‘http://movie’, ‘http://www.movie’);
But it throws the following 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 '://movie’, ‘http://www.movie’)' at line 1
Posting so it can be accepted:
update movies_news set select_page = replace(select_page, ‘http://movie’, ‘http://www.movie’);
contains smart quotes, which are not interpreted as normal single quotes, thus the syntax error. It should instead be
update movies_news set select_page = replace(select_page, 'http://movie', 'http://www.movie');
In general, be really careful about copying code to and from 'smart' text editors (Microsoft Word, etc)

Please resolve the syntax error in the mysql insert query

I am using mysql 5.5.27
At places where it looks like double quotes are two single quotes closer together, and they are actually null values in the excel sheetin the db.
I get the following error,
com.mysql.jdbc.exceptions.jdbc4.MySQLS… 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 'CASE,lname,fname,gender,dob,ssn,… at line 1
the actual query is
Insert into
work(CASE,lname,fname,gender,dob
"CASE" is a reserved word : See http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
You may escape it :
Insert into child(`CASE`,LASTNAME,FIRSTNAME,GENDER,DOB… American','1689 Crucible Street','','Pittsburgh','PA','15210','(4…
But I would personally prefer renaming the column.
CASE is a reserved word ... quote it ..
For mysql:
insert into tableName values()
Anyway you have SQL syntax errors:
Insert into child(CASE,LASTNAME,FIRSTNAME,GENDER,DOB… American','1689 Crucible Street','','Pittsburgh','PA','15210','(4…
Case is a reserwed word: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
In DOB… American' you miss a ' ('DOB… American')