"" and 0 in MySQL

The original paragraph in the article " A Case in which MySQL's Implicit Conversion Causes Weird Phenomenon " reads,

上述例子中 "测试a" 会截成 "",因此 a=0 ,才会返回字段不为空的。

A friend left a message saying, is this sure correct? "Test a" should be converted to 0, not ""?

I think this part is a bit vague, but the conclusion is correct.

Because of the data type problem, "test a" will be converted into a numeric type, and MySQL will automatically truncate it. What should be truncated into "" (empty), it just means that "" and 0 are equal, which can be verified through CAST, "test a" " and '' (empty) are converted to numeric types and both are 0,

select cast('测试a' AS UNSIGNED), CAST('' AS UNSIGNED);

71d06a04d7f9c9c1259b45137db180f3.png

If it is more accurate, it should be said that "test a" is automatically cut into "" (empty), "" and 0 are equal, so we get "a=0".

When it comes to technology, you still have to be more rigorous.

If you think this article is helpful, please feel free to click "Like" and "Reading" at the end of the article, or forward it directly to pyq,

52c1a9caa8d9ac02c1acf36abcfcf76d.png

Recently updated articles:

" A Case Study of MySQL's Implicit Conversion Leading to Weird Phenomenon "

" A SQL scenario where indexing is still very slow in MySQL "

" What is "BRICS"?

" Some Problems Encountered Recently "

" Exploration of MySQL Client Instructions Usage "

Recent hot articles:

" Recommend a classic paper on Oracle RAC Cache Fusion "

" The shock that the open source code of the "Red Alert" game brings to us "

Article classification and indexing:

" Classification and Indexing of 1,200 Public Account Articles "

Guess you like

Origin blog.csdn.net/bisal/article/details/132632577