您的位置:首页 > 数据库 > MySQL

MySQL字符串处理函数的几种常见用法

2016-09-13 15:51 363 查看
1.字符串大小写转化:

(1).将tbl_student表的user_name字段所有小写字母,替换为大写:

update tbl_student set user_name=UPPER(user_name);

(2).将tbl_student表的user_name字段所有大写字母,替换成小写:

update tbl_student set user_name=LOWER(user_name);

2.清除字符串首尾空格,或者指定字符:

(1).清除tbl_student表的user_name字段首尾空格

update tbl_student set user_name=TRIM(' ' from user_name);

(2).清除字符串首部指定字符A:

update tbl_student set user_name=TRIM(LEADING 'A' from user_name);

(3).清除字符串尾部指定字符B

update tbl_student set user_name=trim(TRAILING 'B' from user_name);

3.替换字符串:

(1).替换字符串中的数字1为字母I

update tbl_student set user_name=replace(user_name,'1','I');

4.用正则(REGEXP):

(1).若结尾两个为字母,则去掉

update tbl_student stu stu.user_name=substring(stu.user_name,LENGTH(stu.user_name)-2) where stu.user_name REGEXP '[a-zA-Z]{2,}$';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: