一. 字符串拼接
concat('asdf',str);
說明: 拼接asdf 和 str
二. 字符串截取
- 從左開始截取字符串
left(str, length)
說明:left(被截取字段,截取長度) 例:select left(content,200) as abstract from tablename
- 從右開始截取字符串
right(str,length)
說明:right(被截取字段,截取長度) 例:select right(content,200) as abstract from tablename
- 按長度截取字符串
substring(str, pos) substring(str, pos, length)
說明:substring(被截取字段,從第幾位開始截取) substring(被截取字段,從第幾位開始截取,截取長度) 例: select substring(content,5) as abstract from tablename select substring(content,5,200) as abstract from tablename (注:如果位數是負數 如-5 則是從后倒數位數,到字符串結束或截取的長度)
- 按關鍵字截取字符串
substring_index(str,delim,count)
說明:substring_index(被截取字段,關鍵字,關鍵字出現的次數) 例: SELECT SUBSTRING_INDEX(page ,' ',1) ,page FROM tablename (注:如果關鍵字出現的次數是負數 如-2 則是從后倒數,到字符串結束)
SUBSTRING(str, INSTR(str, delim) + count)
說明: SUBSTRING(被截取的字符串, INSTR(被截取的字符串, 關鍵字) + 關鍵字長度) 例: select SUBSTRING(page, INSTR(page, ' number ') + 8),page from tablename INSTR(字段名, 字符串) 這個函數返回字符串在某一個字段的內容中的位置, 沒有找到字符串返回0,否則返回位置(從1開始) (注: 截取的是關鍵字之后的字符串)
三. 字符串替換
replace(str,original,replace)
說明:replace(字符串,被替換的字符串,替換成的字符串) 例: SELECT replace(street ,’asdf ‘,”) ,street FROM tablename 講street中的asdf替換為空
啦啦啦
