MySQL integer field query string, return all results of 0

Source: Internet
Author: User
Tags truncated

In MySQL, the query string in an integer field returns all results of 0 and should return null or NULL.

For example, table structure information:

CREATE TABLE ' t ' (' name ' char () COLLATE utf8mb4_unicode_ci default NULL, ' ID ' int (one-by-one) not ' null ' engine=innodb default CHARSET=UTF8MB4 Collate=utf8mb4_unicode_ci

Table of data:

Mysql> Select ID from t;+----+|  ID |+----+|  0 | |  0 | | 1 |+----+

Query string A, which returns all of the 0:

Mysql> Select ID from t where id= ' a '; +----+|  ID |+----+|  0 | | 0 |+----+

Warning message:

Mysql> Show warnings;+---------+------+---------------------------------------+| Level | Code | Message |+---------+------+---------------------------------------+| Warning | 1292 | Truncated incorrect DOUBLE value: ' A ' |+---------+------+---------------------------------------+

Query string ' 1a ', can return 1:

Mysql> Select ID from t where id= ' 1a '; +----+|  ID |+----+| 1 |+----+

Alarm information:

Mysql> Show warnings;+---------+------+----------------------------------------+| Level | Code | Message |+---------+------+----------------------------------------+| Warning | 1292 | Truncated incorrect DOUBLE value: ' 1a ' |+---------+------+----------------------------------------+

This situation is not often encountered, the solution is to do in the program data type of judgment, the front end of the value of the check

Welcome to Criticize

This article is from the "Amnesiasun" blog, make sure to keep this source http://amnesiasun.blog.51cto.com/10965283/1931639

MySQL integer field query string, return all results of 0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.