当前位置:网站首页> 避坑:Sql中 in 和not in中有null值的情况说明
避坑:Sql中 in 和not in中有null值的情况说明
2022-07-07 13:11:00 【1024问】
Sql中in和not in中有null值的情况
1.not in 中包含null值的情况
2.in 中包含null值的情况
mysql有默认值但是仍然插入null问题
Sql中in和not in中有null值的情况1)in的逻辑规则是or not in 的逻辑规则是 and
2)判断null 的sql语句为 is not null 或者 is null
3)当遇到 null = null 的判断是时由于不符合null的判断规则,所以结果一定为flase
1.not in 中包含null值的情况select * from A where A.name not in (select B.name from B )
在上面的not in的查询中如果B表的name字段存在空值时,不论何种情况上述语句的查询结果一定为空
2.in 中包含null值的情况select * from A where A.name in (select B.name from B )
在上面的 in 的查询中如果B表的name字段存在空值时,如果A表中存在name字段也存在空值,那么上述语句的查询结果中不会显示A表中的空值
mysql有默认值但是仍然插入null问题今天发现项目中对应的某条记录某一列的值为null,但是针对这条记录这一列的值不应该为null。
检查代码发现是在插入的时候没有对这一列对应的成员变量赋值,即便数据库这一列有默认值,在插入到数据库时依然插入了null。
mysql 的默认值只有在insert语句中没有这个字段时才会生效,如果insert中有插入该字段而该字段取值又为null,null值将被插入到表中,默认值此时失效。
在mybatis开发中通常会直接插入一个表对象,表中所有字段都会插入,因此如果要设置默认值,应该在业务层写逻辑,而不能依赖mysql的default来设置默认值。
另外尽量保证对于数据库的新增应该使用动态的sql来进行操作,这样也能避免上面问题。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- [server data recovery] a case of RAID data recovery of a brand StorageWorks server
- Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
- Niuke real problem programming - Day9
- C 6.0 language specification approved
- CTFshow,信息搜集:web9
- How does the database perform dynamic custom sorting?
- 广州开发区让地理标志产品助力乡村振兴
- [make a boat diary] [shapr3d STL format to gcode]
- [server data recovery] data recovery case of raid failure of a Dell server
- [understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper
猜你喜欢
Briefly describe the working principle of kept
Used by Jetson AgX Orin canfd
CTFshow,信息搜集:web3
数学建模——什么是数学建模
什么是数据泄露
CTFshow,信息搜集:web12
IDA pro逆向工具寻找socket server的IP和port
13 ux/ui/ue best creative inspiration websites in 2022
Yyds dry goods inventory # solve the real problem of famous enterprises: cross line
智汀不用Home Assistant让小米智能家居接入HomeKit
随机推荐
Summer safety is very important! Emergency safety education enters kindergarten
【OBS】RTMPSockBuf_Fill, remote host closed connection.
Niuke real problem programming - day13
[deep learning] semantic segmentation experiment: UNET network /msrc2 dataset
【搞船日记】【Shapr3D的STL格式转Gcode】
CTFshow,信息搜集:web5
buffer overflow protection
⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
"Baidu Cup" CTF competition 2017 February, web:include
用于增强压缩视频质量的可变形卷积密集网络
How to enable radius two factor / two factor (2fa) identity authentication for Anheng fortress machine
Ctfshow, information collection: web8
Pandora IOT development board learning (HAL Library) - Experiment 12 RTC real-time clock experiment (learning notes)
PG基础篇--逻辑结构管理(锁机制--表锁)
【深度学习】语义分割实验:Unet网络/MSRC2数据集
leetcode:648. Word replacement [dictionary tree board + find the shortest matching prefix among several prefixes]
PAT 甲级 1103 Integer Factorizatio
13 ux/ui/ue best creative inspiration websites in 2022
激光雷达lidar知识点滴
Find your own value