MySQL 截取字符串

SUBSTRING

SUBSTRING(s, start, length)    从字符串 s 的 start 位置截取长度为 length 的子字符串

从字符串 Hello World 中的第 2 个位置截取 3个 字符:

eg:select SUBSTRING("Hello World",2,3) as test;

 

 

 注:字符串的索引是从1开始的。

如果第三个参数不传,是从start位置截取到最后

eg:select SUBSTRING("Hello World",2) as test;

 

 SUBSTRING(str FROM pos FOR len) 与上面结果一样,从字符串str的pos位置截取长度为len的子字符串

 

 

posted @ 2019-11-29 16:39  独孤靖云  阅读(3272)  评论(0编辑  收藏  举报