mysql分割字符串split mysql如何用正則表達式,截取字符串?
mysql如何用正則表達式,截取字符串?substring_index(input,split,index):input為要截取的字符,split為分隔符,Index為要截取第index個分隔符左(i
mysql如何用正則表達式,截取字符串?
substring_index(input,split,index):input為要截取的字符,split為分隔符,Index為要截取第index個分隔符左(index為正)或右(index為負)的字符串。
舉例:
"Provider="RiskManagement" finalScore="65" RGID="100397278"" //獲取finalScore的值
1、獲取finalScore右邊的字符
select substring_index("Provider="RiskManagement" finalScore="65" RGID="100397278"","finalScore="",-1)
2、再獲取" RGID="左邊的字符
select substring_index(substring_index("Provider="RiskManagement" finalScore="65" RGID="100397278"","finalScore="",-1),"" RGID="",1)。
MySQL截取和拆分字符串函數(shù)用法示例?
MySQL字符串函數(shù)substring:字符串截取
MySQL 字符串截取函數(shù):left(), right(), substring(), substring_index()。還有 mid(), substr()。其中,mid(), substr() 等價于 substring() 函數(shù),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)