当前位置:网站首页> 避坑: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来进行操作,这样也能避免上面问题。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- Promoted to P8 successfully in the first half of the year, and bought a villa!
- #yyds干货盘点# 解决名企真题:交叉线
- Novel Slot Detection: A Benchmark for Discovering Unknown Slot Types in the Dialogue System
- 数学建模——什么是数学建模
- FFmpeg----图片处理
- Compile advanced notes
- Ffmpeg --- image processing
- Read PG in data warehouse in one article_ stat
- Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
- 一文读懂数仓中的pg_stat
猜你喜欢

CTFshow,信息搜集:web3

【服务器数据恢复】戴尔某型号服务器raid故障的数据恢复案例

Ctfshow, information collection: web5

“百度杯”CTF比赛 2017 二月场,Web:include

Stm32cubemx, 68 sets of components, following 10 open source protocols

【数据挖掘】视觉模式挖掘:Hog特征+余弦相似度/k-means聚类

CTFshow,信息搜集:web14

Cocoscreator operates spine for animation fusion

⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?

知否|两大风控最重要指标与客群好坏的关系分析
随机推荐
With 8 modules and 40 thinking models, you can break the shackles of thinking and meet the thinking needs of different stages and scenes of your work. Collect it quickly and learn it slowly
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
Stm32cubemx, 68 sets of components, following 10 open source protocols
Read PG in data warehouse in one article_ stat
Xiaomi's path of chip self-development
【OBS】RTMPSockBuf_ Fill, remote host closed connection.
CTFshow,信息搜集:web14
2. 堆排序『较难理解的排序』
Ascend 910 realizes tensorflow1.15 to realize the Minist handwritten digit recognition of lenet network
“百度杯”CTF比赛 2017 二月场,Web:include
Cocoscreator operates spine for animation fusion
Lidar Knowledge Drop
【搞船日记】【Shapr3D的STL格式转Gcode】
CTFshow,信息搜集:web4
暑期安全很重要!应急安全教育走进幼儿园
leetcode:648. Word replacement [dictionary tree board + find the shortest matching prefix among several prefixes]
C 6.0 language specification approved
知否|两大风控最重要指标与客群好坏的关系分析
[follow Jiangke University STM32] stm32f103c8t6_ PWM controlled DC motor_ code
[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering