1、从左开始截取字符串
SELECT LEFT(str,len)
str:被截取的字符串
len:截取长度
SELECT LEFT('TF-8220210412003-1', 10)
2、从右开始截取字符串
SELECT RIGHT(str,len)
str:被截取的字符串
len:截取长度
SELECT RIGHT('TF-8220210412003-1', 6)
3、截取特定长度的字符串
SUBSTRING(str,pos)
str:被截取的字符串
pos:从第几位开始截取
SUBSTRING(str,pos,len)
str:被截取的字符串
pos:从第几位开始截取
SELECT SUBSTRING('TF-8220210412003-1', 4)
SELECT SUBSTRING('TF-8220210412003-1', 4, 6)
SELECT SUBSTRING('TF-8220210412003-1', -3)
SELECT SUBSTRING('TF-8220210412003-1', -9, 3)
4、按关键字进行读取
SELECT SUBSTRING_INDEX(str,delim,count)
SELECT SUBSTRING_INDEX('TF-8220210412003-1', '-', 2)
SELECT SUBSTRING_INDEX('TF-8220210412003-1', '-', -2)
SELECT SUBSTRING_INDEX('TF-8220210412003-1', '=', 2)
|