0

The data in the Response column is = blahblahblahTYPE=ERRORblahblah. I then run the query below to just target the 'ERROR' string.

SELECT substr(Response, instr(Response, 'ERROR'), 5) 
  FROM table 
  WHERE id = 721451 
    AND Status = 'false' 
    AND Response LIKE '%<status>Unknown</status>%' 
    AND date >= curdate();

The query above returns: ERROR.

I basically want to update ERROR to SUCCESS without editing the rest of the data.

Would the query below work? Is there a better way to do this?

UPDATE table 
  SET Response = 'SUCCESS' 
  WHERE (
    SELECT substr(Response, instr(Response, 'ERROR'), 5) 
      FROM table 
      WHERE id = 721451 
        AND Status = 'false' 
        AND Response LIKE '%<status>Unknown</status>%' 
        AND date >= curdate()
  );

Thanks for your help in advance!

4

1 回答 1

1
UPDATE table 
  SET Response = REPLACE(Response, 'ERROR', 'SUCCESS')
   WHERE id = 721451 
     AND Status = 'false' 
     AND Response LIKE '%<status>Unknown</status>%' 
     AND date >= curdate();

参考https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

于 2015-08-15T07:04:58.687 回答