specific string change within record

Discussion in 'MySQL' started by bugcoder, Jul 29, 2009.

  1. #1
    i have a field name url with a lot of records in it like this

    http://localhost/scd/app/webroot/blog/?p=26

    and last value is actually id of that record so in fact the record is almost same with just last id change for whole field

    now i want my that field records to be changed to like this

    http://localhost/scd/blog/?p=26

    and i want it to be done using mysql. So that only app/webroot/ can be removed from each record and remaining text remain same.

    can it be done.....................
     
    bugcoder, Jul 29, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If the url at the beginning is always the same, you could use this to update the entire table.

    UPDATE my_table SET url = CONCAT('http://localhost/scd/app/webroot/blog/',SUBSTR(url,36));

    The 36 represents the length of 'http://localhost/scd/blog/' which will be removed. Test this on a few records before performing a full update to make sure it does what you want.
     
    jestep, Jul 29, 2009 IP