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

Research on the problem of SQL query set returning to [null,null]

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

In the Java project, if you query some fields of a table in the database through Mybatis, the return value is list. Sometimes the [null, null] phenomenon occurs.

The specific reason is that the query SQL only fetches some fields, and these fields are null.

But for other fields of the database table, the query has a value, but it just so happens that the field you query is Null.

Execute: SELECT * FROM user2 WHERE name='rtr'

The result is:

A rtr 2019-02-19

B rtr 2019-02-19

Execute: SELECT department_id FROM user2 WHERE name='rtr'

The result is:

Null

Null

Execute: SELECT COUNT (*) FROM

(SELECT department_id FROM user2 WHERE name='rtr') AS t

The result is: 2.

Solution: several fields that need to be queried must be added with a judgment that is not empty.

SELECT department_id FROM user2 WHERE NAME = 'rtr' AND department_id IS NOT NULL

Results: null

SELECT

COUNT ()

FROM

(SELECT FROM user2 WHERE NAME = 'rtr' AND department_id IS NOT NULL) AS t

Result: 0

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

Database

Wechat

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

12
Report