MySQL字串操作

2021-10-10 14:22:35 字數 761 閱讀 1199

【擷取】

1.欄位右側擷取

right(『欄位名』,長度);

select right(user_affiliate,3) from usertable;
2.欄位左側擷取

left(『欄位名』,長度);

select left(user_affiliate,3) from usertable;
3.中間擷取

substring(『欄位名』,開始位置,長度);

//  第一位從1開始

select substring(user_affiliate,6,3) from usertable;

【拼接】

concat(字串,字串…);

select concat(right(user_affiliate,3),user_number) nam from usertable;
【更新】

update中使用select

update usertable  

inner join(select concat(right(user_affiliate,3),user_number) nam,user_id from usertable) c

on usertable.user_id = c.user_id set usertable.user_number = c.nam

mysql 字串操作

函式各函式的功能說明 函式concat s1,s2,返回連線引數產生的字串,乙個或多個待拼接的內容,任意乙個為null則返回值為null。concat ws x,s1,s2,返回多個字串拼接之後的字串,每個字串之間有乙個x。substring s,n,len mid s,n,len 兩個函式作用相同...

Mysql字串操作總結

一 字串連線 1 concat string1,string2,說明 string1,string2代表字串,concat函式在連線字串的時候,只要其中乙個是null,那麼將返回null select concat 1 2 null from dual 結果返回null,select concat ...

json字串操作MySQL

insert yh friendlists user id,friendlist,count values 80 1 update操作 不能像原資料一樣使用 來連線字串json set json merge column,key value json replace shanghai 4 where...