当前位置:网站首页> 避坑: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来进行操作,这样也能避免上面问题。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
猜你喜欢

IDA pro逆向工具寻找socket server的IP和port

如何在opensea批量发布NFT(Rinkeby测试网)

Why do we use UTF-8 encoding?

Pandora IOT development board learning (HAL Library) - Experiment 12 RTC real-time clock experiment (learning notes)
![[deep learning] image hyperspectral experiment: srcnn/fsrcnn](/img/84/114fc8f0875b82cc824e6400bcb06f.png)
[deep learning] image hyperspectral experiment: srcnn/fsrcnn

Unity之ASE实现卡通火焰

Unity之ASE实现全屏风沙效果

Ctfshow, information collection: web2

TypeScript 发布 4.8 beta 版本

Discussion on CPU and chiplet Technology
随机推荐
Ctfshow, information collection: web10
[understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper
JSON parsing instance (QT including source code)
Computer win7 system desktop icon is too large, how to turn it down
Pat grade a 1103 integer factorizatio
数学建模——什么是数学建模
Notes HCIA
众昂矿业:萤石继续引领新能源市场增长
暑期安全很重要!应急安全教育走进幼儿园
激光雷达lidar知识点滴
[deep learning] image hyperspectral experiment: srcnn/fsrcnn
Ascend 910 realizes tensorflow1.15 to realize the Minist handwritten digit recognition of lenet network
leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
[target detection] yolov5 Runtong voc2007 data set
Stm32cubemx, 68 sets of components, following 10 open source protocols
Pandora IOT development board learning (HAL Library) - Experiment 12 RTC real-time clock experiment (learning notes)
智汀不用Home Assistant让小米智能家居接入HomeKit
【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例
缓冲区溢出保护
Ctfshow, information collection: web1