Results 1 to 6 of 6
Thread: "find and replace" in SQL??
Enjoy an ad free experience by logging in. Not a member yet? Register.
"find and replace" in SQL??
the table name is "products" and the column is "products_image"
what SQL query should i use to replace *.jpg with *.gif down the entire column??
i dont know squat about SQL...
Globbing is not a good idea in SQL, as changes remain permanent. You will find there aren't many ways to do it either. There are no for loops in sequel. I would suggest using a select query to take all the details:
use your_database_name select products_image from picture
update products set products_image = '1234.gif' where products_image = '1234.jpg' update products set products_image = '321.gif' where products_image = '321.jpg'
It's not how any coder likes to do things, but with SQL I never take chances.
PS Don't forget to backup before any bulk inserts!
08-09-2006 #3Originally Posted by bigtomrodney
can i do *.jpg and *.gif????
Well the wildcard in SQL is % rather than * when you are working with strings. * means all. I'm not sure if it would work to do a %.jpg/%.gif. I know you can embed mysql statements into bash, maybe someone here can jump in and take over. Unfortunately my SQL experience is mainly from MSSQL Server, and I haven't done much with MySQL on and Unix systems.
08-10-2006 #5Originally Posted by bigtomrodney
- Join Date
- Aug 2006
I was looking for the same thing kinda...
Here is what I got:
SET products_image = stuff(products_image,len(products_image)-3,3,'gif')
where (products_image like '%.jpg')
Please note - I used this on SQL server
You may have to fudge around with the numbers to lop-off the jpg and insert the gif.
Hope this helps