mysql 常用的函数方法concat,substr,substring,substring_index,left,right,
分享于 点击 33471 次 点评:211
mysql 常用的函数方法concat,substr,substring,substring_index,left,right,
concat用法:
concat(str1,str2)返回字符串参数连接后的结果
eg:select concat(user_name,score) as newname from test1; ==>将user_name和score字段连接起来
substr用法:
mysql: substr(),substring()
oracle: substr()
sql server: substring()
substr(str,pos,len)//substr(str from pos for len) str从pos位置开始截取到len位置,注:pos第一个下标是1.
eg:select substr(t.user_name,1,3) as newname from test1 t; ==》取test1中的user_name字段,从第一个字符取到第三个字符,故取前三位字符
substring_index用法:
substring_index(str,delim,count):按某些字符的下标来截取字符串eg:select substring_index(mobile,',',1) from test1 a; ==>mobile列按‘,’取,只取1个数量.故只显示第一个逗号前的数据
left用法:
left(str,len)从左边截取len长度字符串
eg:select left(t.mobile,4) from test1 t; ==>从mobile列中从左边取4个字符
right用法:
right(str,len)从右边截取len长度字符串
eg:select right(t.mobile,4) from test1 t; ==>从mobile列中从右边取4个字符
相关文章
- 暂无相关文章
用户点评