当前位置:网站首页>Data problems can also be found if there is a space at the end of the field value of MySQL query criteria
Data problems can also be found if there is a space at the end of the field value of MySQL query criteria
2022-07-28 01:17:00 【Big dream_ Thousands of autumn】
mysql Data problems can also be found if there is a space at the end of the field value of the query criteria
1、 Problem description
I encountered a problem in my work today , The production environment has a null pointer exception when calling a scheduled task , After investigation, it was found that mysql Data can also be found if there is a space at the end of the field value of the query criteria . and map in key Is a value with spaces , If you can't get the null pointer . Here's a replay
Here are two people with the same name in my library , A name followed by a space , A name without spaces . This 1 To see the blank space effect in the screenshot 
SELECT * FROM `student` where studentname = ' Zhang Wei ';
Here, the person who queries the field without spaces will query the person who has spaces at the end of the field 
Here is the person with a space at the end of the query field
SELECT * FROM `student` where studentname = ' Zhang Wei ';
Query results 
2、 Question why
The reason for this problem is : If the field is char or varchar type , So when comparing strings MySQL Use PADSPACE Proofread rules , The space character at the end of the field is ignored , Whether it is followed by a space or multiple
3、 The solution to the problem
3.1、 from SQL To solve the problem
- Use the compared value BINARY Function to binary
SELECT * FROM `student` where studentname = BINARY' Zhang Wei ';
- Use length Function to compare ( Large quantities of data will affect efficiency )
SELECT * FROM `student` where studentname = ' Zhang Wei ' and LENGTH(studentname) = LENGTH(' Zhang Wei ');
- Use like function
SELECT * FROM `student` where studentname like ' Zhang Wei ';
3.2、 from Java Aspect avoidance
from Java The way to avoid this aspect is to use the time string input parameter of the query trim() Method to remove white space , At the same time, the results of the query should also deal with spaces
边栏推荐
- Shaanxi Yuanjie semiconductor, a laser chip manufacturer, was invested by 8 investment institutions including GF Securities and CITIC Securities
- 美光起诉联电窃密案宣判:联电被罚1亿元新台币,三名员工被判刑!
- ABAP CDS Table Function介绍与示例
- Gossip: an initially perfect FS is as impractical as the first version of the program requiring no bugs
- Basic concept and classification of i/o equipment
- Spool timer
- Detailed explanation of retinanet network structure
- [STM32] watchdog module
- 0-1 knapsack problem
- Sign up now | cloud native technology exchange meetup Guangzhou station has been opened, and I will meet you on August 6!
猜你喜欢

测试人员需要了解的软件流程

Postman 的使用

Examples of application of JMeter in performance testing

Ford SUV "Mustang" officially went offline, safe and comfortable

EWM收货ECC交货单校验逻辑问题

共创文旅新篇章|新起典与国华文旅签订战略合作协议

Storage of deep planing data in memory

Wavelet transform learning notes

杂谈:一份最初就非常完善的FS跟第一版程序就要求没bug一样不切实际

I/O设备的基本概念及分类
随机推荐
Maximize activation
0-1背包问题
杂谈:一份最初就非常完善的FS跟第一版程序就要求没bug一样不切实际
Scrollview, tableview nested solutions
力挺吴雄昂!Arm中国管理层发公开信:对莫须有的指控感到震惊和愤怒!
Fabric2.4.4 version building process (complete process)
Vandermond convolution learning notes
工具函数:把一个工作区中非空字段值付给另一个工作区相同字段
重新定义分析 - EventBridge 实时事件分析平台发布
Swoole collaboration
Introduction to the browser video frame operation method requestvideoframecallback()
C语言程序设计 | offsetof宏的讲解及其模拟实现
文件系统挂载
System clock failure of database fault tolerance
Hierarchy of file system
The cooperation between starfish OS and metabell is just the beginning
If asynchronous processing is implemented according to the framework
Iperf installation and use
Redis cache penetration breakdown and avalanche
Brief analysis of advantages, disadvantages and development of SAP modules