开发者

Mysql Update Field Contents

开发者 https://www.devze.com 2022-12-14 14:09 出处:网络
I am currently trying to edit my db named boh. The current table \"files\" has a field called \"path\". Inside the path field is an actualpath to files listed in a folder, syntax \"F:\\xxx\\xxx\\xxx\\

I am currently trying to edit my db named boh. The current table "files" has a field called "path". Inside the path field is an actualpath to files listed in a folder, syntax "F:\xxx\xxx\xxx\filename.xxx". How do I update the field information to replace the "F:\xxx\xxx\xxx" so that just the f开发者_如何转开发ile name exists?


It depends what you exactly want, if you want to strip constant path you can use:

UPDATE `table` SET `path` = REPLACE(`path`, 'F:\\xxx\\xxx\\xxx', '');

If you want to keep only last part after last \, then following command should do it:

UPDATE `table` SET `path` = SUBSTRING_INDEX(`path`. '\\', -1);


did you read this?

http://dev.mysql.com/doc/refman/5.1/en/replace.html


UPDATE files
SET path = REPLACE(path, 'F:\xxx\xxx\xxx\', '')
WHERE path LIKE = 'F:\xxx\xxx\xxx\%'

It's very easy to ruin your data with this massive updates so make sure you:

  • Try it first with a SELECT sentence
  • Backup your data


Assuming 'F:\xxx\xxx\xxx\' is not constant you could try a statement like this one:

UPDATE files SET path = REVERSE(SUBSTR(REVERSE(path), 1, LOCATE(REVERSE(path), '\')));
0

精彩评论

暂无评论...
验证码 换一张
取 消