Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Varchar of MYSQL and Analysis of numerical examples

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly talks about "varchar and numerical example Analysis of MYSQL". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "varchar and numerical example Analysis of MYSQL".

The origin of events

All right, let's talk about the specific scene. I was asked by a colleague to see a strange SQL. The SQL statement is simple, probably just querying some fields with some query conditions. One of the more important conditions is "where xxx conditions 0". Said it was very strange, why! When = 0, the query result is 10. But! The query result of = 1 is 100.

SELECT Amena Brecinct C FROM TABLE WHERE Achievement 0

Res:10

SELECT Amena Brecinct C FROM TABLE WHERE Achievement 0

Res:100

Let's briefly take a look at the situation.

Recurrence of the situation

"all data"

"! = 0"

At that time, we got such a result directly.

Analyze the situation

At that time, I was also surprised to see this problem. Isn't it equal to zero? shouldn't we get all the data? Why did this happen?

After a brief consideration, the field is of type varchar, and the query condition is given a numeric type, so that's where the problem should be.

How does the database operate when it is retrieved based on query conditions?

The answer is to convert to the same type.

So the question this time is whether the field is converted to int or int to varchar? In fact, you can simply look at the query results. If the query condition'0' is converted to varchar, then you should get all the data. But the current situation is that the data obtained is not enough. The conclusion is that the database converts the fields to be queried into numeric values.

So let's try to convert the app field.

From the results, we can see that after the app conversion, only 0123asfj is converted to 123, and the rest is 0. So the query condition is'! When = 0', only one result can be queried.

At this point, I believe you have a deeper understanding of "varchar and numerical example Analysis of MYSQL". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report