本文介紹了MySQL在使用長(zhǎng)類型數(shù)字過(guò)濾varchar類型時(shí)返回額外記錄的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
一個(gè)簡(jiǎn)單的表格:
CREATE TABLE `tbl_type_test` (
`uid` varchar(31) NOT NULL DEFAULT '0',
`value` varchar(15) NOT NULL DEFAULT '',
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
和一些記錄:
'6011656821812318924', 'a'
'6011656821812318925', 'b'
'6011656821812318926', 'c'
當(dāng)我執(zhí)行下面的SQL時(shí),會(huì)返回3條記錄
when I execute the following SQL, 3 records will return
select * from tbl_type_test where uid = 6011656821812318924;
這也將返回 3 條記錄.奇怪.
and this will return 3 records, too. Weird.
select * from tbl_type_test where uid = 6011656821812318900;
如果我將數(shù)字更改為字符串類型,如預(yù)期的那樣,只會(huì)返回 1 條記錄:
if I change the number to string type, as expected, only 1 record will return:
select * from tbl_type_test where uid = '6011656821812318924';
我認(rèn)為查詢中的數(shù)字類型和長(zhǎng)度是原因,但我不知道確切的原因.
I think the number type and length in the query is the reason, but I don't known the exact.
任何評(píng)論將不勝感激.
推薦答案
在所有其他情況下,參數(shù)作為浮點(diǎn)(實(shí)數(shù))數(shù)進(jìn)行比較. - https://dev.mysql.com/doc/refman/5.7/en/type-conversion.html
例如
drop procedure if exists p;
delimiter $$
create procedure p (inval float, inval2 float, inval3 float)
select inval,inval2,inval3;
call p(6011656821812318924,6011656821812318925,6011656821812318926);
+------------+------------+------------+
| inval | inval2 | inval3 |
+------------+------------+------------+
| 6.01166e18 | 6.01166e18 | 6.01166e18 |
+------------+------------+------------+
1 row in set (0.00 sec)
這篇關(guān)于MySQL在使用長(zhǎng)類型數(shù)字過(guò)濾varchar類型時(shí)返回額外記錄的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!