MySQL 字符串截取
来源:互联网 发布:软件的数学模型 编辑:程序博客网 时间:2024/06/15 09:04
1、从左开始截取字符串
left(str, length)
说明:left(被截取字段,截取长度)
例:select left(content,200) as abstract from my_content_t
2、从右开始截取字符串
right(str, length)
说明:right(被截取字段,截取长度)
例:select right(content,200) as abstract from my_content_t
3、截取字符串
substring(str, pos)
substring(str, pos, length)
说明:substring(被截取字段,从第几位开始截取)
substring(被截取字段,从第几位开始截取,截取长度)
例:select substring(content,5) as abstract from my_content_t
select substring(content,5,200) as abstract from my_content_t
(注:如果位数是负数 如-5 则是从后倒数位数,到字符串结束或截取的长度)
4、按关键字截取字符串
substring_index(str,delim,count)
说明:substring_index(被截取字段,关键字,关键字出现的次数)
例:select substring_index("blog.jb51.net","。",2) as abstract from my_content_t
结果:blog.jb51
(注:如果关键字出现的次数是负数 如-2 则是从后倒数,到字符串结束)
left(str, length)
说明:left(被截取字段,截取长度)
例:select left(content,200) as abstract from my_content_t
2、从右开始截取字符串
right(str, length)
说明:right(被截取字段,截取长度)
例:select right(content,200) as abstract from my_content_t
3、截取字符串
substring(str, pos)
substring(str, pos, length)
说明:substring(被截取字段,从第几位开始截取)
substring(被截取字段,从第几位开始截取,截取长度)
例:select substring(content,5) as abstract from my_content_t
select substring(content,5,200) as abstract from my_content_t
(注:如果位数是负数 如-5 则是从后倒数位数,到字符串结束或截取的长度)
4、按关键字截取字符串
substring_index(str,delim,count)
说明:substring_index(被截取字段,关键字,关键字出现的次数)
例:select substring_index("blog.jb51.net","。",2) as abstract from my_content_t
结果:blog.jb51
(注:如果关键字出现的次数是负数 如-2 则是从后倒数,到字符串结束)
函数简介:
SUBSTRING(str,pos) , SUBSTRING(str FROM pos) SUBSTRING(str,pos,len) , SUBSTRING(str FROMpos FOR len)
不带有len 参数的格式从字符串str返回一个子字符串,起始于位置 pos。带有len参数的格式从字符串str返回一个长度同len字符相同的子字符串,起始于位置pos。 使用 FROM的格式为标准 SQL 语法。也可能对pos使用一个负值。假若这样,则子字符串的位置起始于字符串结尾的pos 字符,而不是字符串的开头位置。在以下格式的函数中可以对pos 使用一个负值。
0 0
- mysql截取字符串
- MySQL截取字符串
- mysql字符串截取
- mysql 截取字符串
- mysql截取字符串
- MySQL 字符串截取函数
- Mysql字符串截取函数
- MySQL截取字符串函数
- mysql字符串截取
- mysql 截取字符串
- Mysql截取字符串
- MySQL 字符串截取函数
- mysql字符串截取
- MySql字符串截取
- mysql字符串截取:
- MySQL 字符串截取函数
- mysql截取字符串
- mysql截取字符串
- 页面table转存为pdf
- React+Redux 学习
- Fragment简介及使用注意事项
- 【NOIP2014八校联考第1场第2试】大水题(water)
- git回退历史记录总结
- MySQL 字符串截取
- 学以致用:批量下载豆瓣线上活动图片
- 状态模式
- struts2 组成结构
- float浮动的特性以及清除浮动
- 【JZOJ3824】【NOIP2014模拟9.9】渴
- OpenCV InputArray和OutputArray
- 应用程序刷新surface时到sf的送显流程
- 2017.1.15【初中部 】普及组模拟赛C组 小x的数列 题解