一條 update 語句引起的事故,這回讓開發(fā)長長記性!

一、前言
二、過程
update tablename set source_name = "bj1062-北京市朝陽區(qū)常營北辰福第"where source_name = "-北京市朝陽區(qū)常營北辰福第"
bj1062,是真的沒有錯(cuò)誤么?是的沒有錯(cuò)誤。開發(fā)執(zhí)行完成后,結(jié)果的確是符合預(yù)期。Harvey,我執(zhí)行了update,where條件都是對的,set的值也是對的,但是set后的字段全部都變成了0,你趕緊幫我看看,看看能不能恢復(fù)數(shù)據(jù)。


update tbl_name set str_col="xxx" = "yyy"
update tbl_name set (str_col="xxx" )= "yyy"
update tbl_name set str_col=("xxx" = "yyy")
select "xxx" = "yyy"
update tbl_name set str_col="xxx" = "yyy"
update tbl_name set str_col=0
mysql [localhost] {msandbox} (test) > select id,str_col from tbl_name where str_col="xxx" = "yyy";+----+---------+| id | str_col |+----+---------+| 1 | aaa || 2 | aaa || 3 | aaa || 4 | aaa |+----+---------+
mysql [localhost] {msandbox} (test) > warningsShow warnings enabled.mysql [localhost] {msandbox} (test) > explain extended select id,str_col from tbl_name where str_col="xxx" = "yyy"\G*************************** 1. row ***************************id: 1select_type: SIMPLEtable: tbl_nametype: indexpossible_keys: NULLkey: idx_strkey_len: 33ref: NULLrows: 4filtered: 100.00Extra: Using where; Using index1 row in set, 1 warning (0.00 sec)Note (Code 1003): /* select#1 */ select `test`.`tbl_name`.`id` AS `id`,`test`.`tbl_name`.`str_col` AS `str_col` from `test`.`tbl_name` where ((`test`.`tbl_name`.`str_col` = 'xxx') = 'yyy')
((`test`.`tbl_name`.`str_col` = 'xxx') = 'yyy')
然后0或者1再和和’yyy’進(jìn)行判斷,
由于等號一邊是int,另外一邊是字符串,兩邊都轉(zhuǎn)化為float進(jìn)行比較,可以看我之前的一篇文章
MySQL中隱式轉(zhuǎn)換導(dǎo)致的查詢結(jié)果錯(cuò)誤案例分析
‘yyy’轉(zhuǎn)化為浮點(diǎn)型為0,0和0比較恒等于1
mysql [localhost] {msandbox} (test) > select 'yyy'+0.0;+-----------+| 'yyy'+0.0 |+-----------+| 0 |+-----------+1 row in set, 1 warning (0.00 sec)mysql [localhost] {msandbox} (test) > select 0=0;+-----+| 0=0 |+-----+| 1 |+-----+1 row in set (0.00 sec)
select id,str_col from tbl_name where 1=1;
三、小結(jié)
大家覺得有所幫助希望可以動(dòng)動(dòng)手指點(diǎn)贊、分享、收藏、留言呀。
—————END————— 推薦閱讀: Spring Boot 集成 Swagger-Bootstrap-UI IDEA下創(chuàng)建SpringBoot項(xiàng)目實(shí)現(xiàn)動(dòng)態(tài)登錄與注冊功能 老大懟我好幾次,不要隨便提 “分庫分表” 23 種設(shè)計(jì)模式的通俗解釋,雖然有點(diǎn)污,但是秒懂 最近面試BAT,整理一份面試資料《Java面試BAT通關(guān)手冊》,覆蓋了Java核心技術(shù)、JVM、Java并發(fā)、SSM、微服務(wù)、數(shù)據(jù)庫、數(shù)據(jù)結(jié)構(gòu)等等。 獲取方式:關(guān)注公眾號并回復(fù) java 領(lǐng)取,更多內(nèi)容陸續(xù)奉上。 明天見(??ω??)??
評論
圖片
表情
