I'm trying to do this in mysql . How can I replace parts of a string in a column in MYSQL with 1000 records. Change all records form .JPG to .gif
eg. DC3444.JPG to DC3444.gif
update your_table
set some_column = replace(some_column, '.JPG', '.gif')
UPDATE table1 SET col1 = REPLACE(col1, '.JPG','.gif')
Use this as reference : http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_replace
Related
I am trying to make an update on a DB replacing old characters for new ones, my problem is that at the middle of that string I have some characters I have to remove but I dont know the length or the type, I just know when the sub string starts and when it ends, for exmaple
my-string=XXXXXXXX-endstring
so, Id like to make it like this
new-string-endstring
I know my-string value, but dont know the sub string in the middle XXXXX
is there any way to do it?
Thanks.
Update fields which begin with my-string- AND end with -endstring:
UPDATE table_name
SET column_name = 'new-string-endstring'
WHERE column_name LIKE 'my-string-%'
AND column_name LIKE '%-endstring';
If you use PHP you could do the following:
1) Make a SELECT of all rows that have the my-string text inside the column value
SELECT * FROM table_name WHERE column_name LIKE '%my-string%'
the % acts as a wildcard
2) Loop through all these result rows and use PHP's str_replace to replace my-string for new_string, and then use MySQL's UPDATE to update the new value of the column in the DB
You can use SUBSTRING_INDEX to get the required string and use CONCAT to append new string.
Update TableA
Set columnA = CONCAT( 'newstring' , SUBSTRING_INDEX(columnA, '-', -1) )
I have data with 6 characters like 123456 in a mysql database. I want to change the existing data like 123,456 . Is there any mysql query can do this. Because i want to change over 3000 records.
Try this, it will FORMAT your numbers regardless of the number of digits:
UPDATE yourtable
SET yourfield = FORMAT(yourfield,0)
Try this :
UPDATE yourtable
SET yourfield = LEFT(yourfield,3) + ',' + RIGHT(yourfield,3)
it will do what you asked for. Note it won't help if your field is not 6 characters long
update mytable set
mycolumn = replace(mycolumn, ',', '')
Lets say that you have the following stored in table:
{2:22}{4:5}{34:4}
I what to delete {4:5} from this string but the system dosent know what the number after the ":" is just the first one. The query looks something like this:
UPDATE tbl SET this = REPLACE(this,'{4:??}','') WHERE id = 1;
What do i need to put in ?? place to return the following result?
{2:22}{34:4}
Here's one way to do it using LEFT, SUBSTRING, LOCATE and REPLACE:
update yourtable
set yourcolumn =
replace(yourcolumn,
Left(
Substring(yourcolumn,
Locate('{4:',yourcolumn),
Length(yourcolumn)),
Locate('}',Substring(yourcolumn,
Locate('{4:',yourcolumn),
Length(yourcolumn)))),
'')
SQL Fiddle Demo
I have a column in my table named title_id with some title ids. Each title id is stored like
title_1
title_2
title_3
where 1, 2, 3 are the actual ids of the titles.
I want to remove the " title_ " text from all the records. I have around 5000 records so I can't edit them manually.
How can I do it with a query.
Thanks in advance
Update table_name set `title_id` = REPLACE(`title_id`,'title_','');
I didnt' tested it . Please check
UPDATE table_name SET title_id = REPLACE(title_id, 'title_','')
Check out the REPLACE function. You can do something like:
UPDATE table
SET title_id = REPLACE(title_id, 'title_', '');
(Ah, and be sure to first test your UPDATE query by running a SELECT query!)
Try something like
update table_name set id=substring(id, from length('title_'))
where id like 'title%';
I didn't test this, because I have no MySQL DB available here. The syntax for the substring function is from the MySQL docs.
I'm trying to find certain text "catid=18" in a string, where each string is different except for this.
I've used this query below before, except it only seems to work if you know the entire string.
update TABLE_NAME
set FIELD_NAME = replace(FIELD_NAME, 'findthis', 'replacewiththis');
Not sure if that is what you want. But it will return 1 if catid=any_num is found and 0 if not:
select 'some_text catid=18 some_text' REGEXP 'catid=[0-9]+'
Maybe you need:
update TABLE_NAME
set FIELD_NAME = 'goodvalue'
WHERE FIELD_NAME = 'badvalue';