java web MySQL截取和拆分字符串函数用法示例?

MySQL截取和拆分字符串函数用法示例?MySQL字符串函数substring:字符串截取MySQL 字符串截取函数:left(), right(), substring(), substring_i

MySQL截取和拆分字符串函数用法示例?

MySQL字符串函数substring:字符串截取

MySQL 字符串截取函数:left(), right(), substring(), substring_index()。还有 mid(), substr()。其中,mid(), substr() 等价于 substring() 函数,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 |

--------------------------

实例:

#查询某个字段后两位字符

select right(last3, 2) as last2 from historydata limit 10

#从应该字段取后两位字符更新到另外一个字段

update `historydata` set `last2`=right(last3, 2)

Mysql字符串截取函数SUBSTRING的用法说明?

Oracle截取字符串的函数为:substr(字段名,起始位置,字符串长度) 起始位置可从0开始,截取结果和从1开始一样。MySql截取字符串的函数为:substring(字段名,起始位置,字符串长度) 起始位置必须从1开始,0开始不能获取到数据。