首页 > 代码库 > MySQL 字符串截取函数;

MySQL 字符串截取函数;

*left(), right(), substring(), substring_index(),mid(), substr(),mid(), substr() 等价于 substring() 函数

技术分享
1. 字符串截取:left(str, length)

mysql> select left(‘example.com‘, 3);
+-------------------------+
| left(‘example.com‘, 3) |
+-------------------------+
| exa                     |
+-------------------------+
2. 字符串截取:right(str, length)

mysql> select right(‘example.com‘, 3);
+--------------------------+
| right(‘example.com‘, 3) |
+--------------------------+
| com                      |
+--------------------------+
//从一个字段取后两位字符更新到另外一个字段
update `historydata` set `last2`=right(last3, 2);
View Code

 

_________

MySQL 字符串截取函数;