Replace word in the middle of mysql field

Discussion in 'MySQL' started by ridesign, Sep 8, 2008.

  1. #1
    In my database some of the GBP pound signs have a symbol infront like: £199.99 this was due to some encoding problem which I have fixed, but is there a way to edit all the current entries in the database with a sql query to remove the sign?
    I though of doing
    UPDATE dbname SET field1 = £ WHERE field1 LIKE "%£";
    Code (markup):
    but this will remove all of the text in the field and replace it with just £

    Example of Text field:field1
    120w X 5 Black £199.99 New Demo
    Code (markup):

     
    ridesign, Sep 8, 2008 IP
  2. superjacent

    superjacent Peon

    Messages:
    98
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    BACKUP....BACKUP....BACKUP....


    UPDATE tablename SET tablefield = replace(tablefield,"findstring","replacestring");

    Oh, and did I mention to backup first.
     
    superjacent, Sep 8, 2008 IP
    ridesign likes this.
  3. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #3
    WOW, I didn't know you could do that! Sweet!
     
    clinton, Sep 8, 2008 IP
  4. superjacent

    superjacent Peon

    Messages:
    98
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I should have added I tested this against MySql and it worked.
     
    superjacent, Sep 8, 2008 IP
  5. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for sharing. I have got a general ideal about how to replace the character. I can slove the problem more quick if I encounter this problem.
     
    justinlorder, Sep 8, 2008 IP