前幾天主管給我說,有一筆資料有誤,讓我撈取更新一下,我默默的點了點頭說好,查詢了一下資料庫,幾萬筆資料,怎麼改?我就懵掉了,磨磨唧唧實在沒辦法,催的又急。
我便說我這鏈結工具有問題,讓主管幫我改一下,呆在旁邊,便看見這個函式concat,
~~哈哈,將函式寫在手心學習記載一下。
語法:concat(『str1』,『str2』,『str』)
函式使用說明:
返回不同的非null 值數目。若找不到匹配的項,則count(distinct) 返回 0項。
1、concat函式拼接如下,拼接完成123。
具體條數,依據查詢的條數生成。select concat
('1'
,'2'
,'3'
) from resource_file;
-- 結果集
concat
('1'
,'2'
,'3'
)123
123.
..
2、當查詢拼接值為空時,返回值為空。
3、concat的sql注入。批量操作注入sql語句,用於批量更新,插入等操作。select concat
('1'
,'2'
,'null'
,'3'
) from resource_file;
-- 結果集
concat
('1'
,'2'
,'null'
,'3'
)null
null..
.
如上查詢的結果集,需要保證查詢的結果集在其中。
將concat函式替換*。
執行sql便會完成多條更新語句,將其複製出來執行。select
concat
('update rrcba set rrcba05="'
,rrcga10,
'" where id="'
,cba.id,
'";'
)-- 這裡是更換*的concat函式,裡面資料**於結果集。
from
( select rrcb14, id, rrcb02 from rrcb where rrcb14 not like '%yjgoodjob%' and rrcb06 =
'hc'
) tleft join rrcba cba on rrcb02 = rrcba02
left join rrcga on rrcga.id = rrcb14
where
rrcba04 =
'1'
執行結果如下:
在同張表內的字段直接update更新,這樣的方式,適合不同表之間的集合。update rrcba set rrcba05=
"2019-01-23 10:09:00" where id=
"ff8080816989985d016989b0ea60009c"
;update rrcba set rrcba05=
"2019-01-23 10:09:00" where id=
"ff8080816989985d016989b269c500a6"
;update rrcba set rrcba05=
"2019-01-23 10:09:00" where id=
"ff8080816989985d016989b2a66600a7"
;update rrcba set rrcba05=
"2019-01-23 10:09:00" where id=
"ff8080816989985d016989b2cdd400a8"
;update rrcba set rrcba05=
"2019-01-23 10:09:00" where id=
"ff8080816989985d016989b2f83700aa"
;update rrcba set rrcba05=
"2019-01-23 10:09:00" where id=
"ff8080816989985d016989b315a500ac"
;update rrcba set rrcba05=
"2019-01-23 10:09:00" where id=
"ff8080816989985d016989b3322200af"
;update rrcba set rrcba05=
"2019-01-23 10:09:00" where id=
"ff8080816989985d016989b350ee00b2"
;update rrcba set rrcba05=
"2019-01-22 09:07:00" where id=
"ff8080816989985d016989b36e0900b4"
;update rrcba set rrcba05=
"2019-01-22 09:07:00" where id=
"ff8080816989985d016989b38c3600b6"
;update rrcba set rrcba05=
"2019-01-22 09:07:00" where id=
"ff8080816989985d016989b3ab9700b7"
;update rrcba set rrcba05=
"2019-01-22 09:07:00" where id=
"ff8080816989985d016989b3caba00b9"
;update rrcba set rrcba05=
"2019-01-22 09:07:00" where id=
"ff8080816989985d016989b3ee2e00ba"
;update rrcba set rrcba05=
"2019-01-22 09:07:00" where id=
"ff8080816989985d016989b40e2a00bb"
;
面向開發過程,記錄學習之路。
mysql語法 concat函式
mysql concat str1,str2,返回結果為連線引數產生的字串。如有任何乙個引數為null 則返回值為 null。或許有乙個或多個引數。如果所有引數均為非二進位制字串,則結果為非二進位制字串。如果自變數中含有任一二進位制字串,則結果為乙個二進位制字串。乙個數字引數被轉化為與之相等的二進位...
mysql函式之 concat 多個字段拼接
mysql的查詢結果行欄位拼接,可以用下面兩個函式實現 select concat o.user code,o.user name from sys user o where id 10select concat ifnull o.is admin,o.user name from sys user...
MySQL之CONCAT 的用法
mysql concat 函式用於將多個字串連線成乙個字串,是最重要的mysql函式之一,下面就將為您詳細介紹mysql concat 函式,供您參考 mysql concat str1,str2,返回結果為連線引數產生的字串。如有任何乙個引數為null 則返回值為 null。或許有乙個或多個引數。...