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. 字符串截?。簂eft(str, length)
mysql> select left("example.com", 3)
-------------------------
| left("example.com", 3) |
-------------------------
| exa |
-------------------------
2. 字符串截?。簉ight(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開始不能獲取到數據。