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个字符

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值