1、locate函数可以实现类似indexof的功能,locate(substr,str)返回substr子串在字符串str中的位置。
2、substring函数,截取字符串:
substring(str, pos) substring(str, pos, length) 说明:substring(被截取字段,从第几位开始截取) substring(被截取字段,从第几位开始截取,截取长度)
3、按关键字截取字符串 : substring_index(str,delim,count) 说明:substring_index(被截取字段,关键字,关键字出现的次数) 例:select substring_index(”blog.jb51.net”,”.”,2) as abstract from my_content_t 结果:blog.jb51
mysql> select LOCATE('_',area_code),area_code,substring_index(area_code,'_',1),substring(area_code,1,LOCATE('_',area_code)-1) from rtb_report_area where id<348;
+-----------------------+---------------------+----------------------------------+------------------------------------------------+
| LOCATE('_',area_code) | area_code | substring_index(area_code,'_',1) | substring(area_code,1,LOCATE('_',area_code)-1) |
+-----------------------+---------------------+----------------------------------+------------------------------------------------+
| 6 | cn024_0415_[ln_dd] | cn024 | cn024 |
| 6 | cn024_0417_[ln_yk] | cn024 | cn024 |
| 6 | cn025_0518_[js_lyg] | cn025 | cn025 |
| 7 | cn0311_0314_[hb_cd] | cn0311 | cn0311 |
| 7 | cn0551_0559_[ah_hs] | cn0551 | cn0551 |
| 6 | cn028_0826_[sc_ga] | cn028 | cn028 |
+-----------------------+---------------------+----------------------------------+------------------------------------------------+
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/188546.html原文链接:https://javaforall.cn