LoginSignup
115
80

More than 5 years have passed since last update.

MySQLでレコードに登録された文字列を置換する

Last updated at Posted at 2015-04-16

MySQLでレコードに登録してある文字列を置換したい時に便利な関数。

文字列置換関数

REPLACE(str,from_str,to_str)

strに含まれる文字列from_strをすべて文字列to_strに置換した文字列を返す関数。

使い方

以下のようにすれば、user_dataテーブルのID8のimage_pathカラムの文字列を変更する事ができる。

UPDATE user_data SET image_path=REPLACE(image_path, "/img/", "/") WHERE id=8;

以下のように変更される。

Before
/img/path/hoge.jpg
After
/path/hoge.jpg
115
80
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
115
80