本文介紹了MySQL在使用長類型數字過濾varchar類型時返回額外記錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
一個簡單的表格:
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'
當我執行下面的SQL時,會返回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;
如果我將數字更改為字符串類型,如預期的那樣,只會返回 1 條記錄:
if I change the number to string type, as expected, only 1 record will return:
select * from tbl_type_test where uid = '6011656821812318924';
我認為查詢中的數字類型和長度是原因,但我不知道確切的原因.
I think the number type and length in the query is the reason, but I don't known the exact.
任何評論將不勝感激.
推薦答案
在所有其他情況下,參數作為浮點(實數)數進行比較. - 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)
這篇關于MySQL在使用長類型數字過濾varchar類型時返回額外記錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!