3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【mysql】文字列関連の関数

Last updated at Posted at 2014-02-05

文字列結合

concatの例
select concat(last_name,' ',first_name) from users;
  • 備考1

oracleの||は使えないので注意。
ただし、SQLモードを変更すれば||も使用できる。SQLモードの変更方法はコメント参照。

  • 備考2

concatのパラメータにひとつでもnullがある場合、戻り値はnullになってしまう。対策としてはifnullを併用する。

パラメータにnullが存在する場合
select concat(ifnull(last_name,""),' ',ifnull(first_name,"")) from users;

参考:nullを含むフィールドのconcat

置換

replaceの例
select replace(last_name,'11','00') from users;
3
3
2

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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?