当前位置:网站首页>MYSQL模糊匹配1,11,111这种相似字符串问题
MYSQL模糊匹配1,11,111这种相似字符串问题
2022-07-17 05:02:00 【小新爱编程】
问题分析
今天遇到一个模糊匹配的问题,一般来说直接上 LIKE"%1%" 这种情况就行了。
SELECT * FROM AFTFACT_TIMELY_OPT_DATADIVISION WHERE SCOPE_USER LIKE "%1%"

但是执行了以下,发现下面并没有1的数据,但是缺查出来了,原来下面有11,111这种数据,因为LIKE是模糊匹配,并没有太多限制条件,所以就出现了这种情况,111,11也一并查询出来了。
现在问题已经发现,要进行解决问题。
问题解决
CONCAT功能实现是可以将多个字符串连接成一个字符串,这个时候我们就需要想一下concat拼接的问题,是不是加一下拼接的东西这个功能我们就可以实现,然后就得到了下面问题解决和实现。
SELECT * FROM AFTFACT_TIMELY_OPT_DATADIVISION WHERE CONCAT(",",SCOPE_USER,",") LIKE "%,1,%"

只需要在执行字段前后加上了英文的都好,这样执行下来就不会出现上次情况了,查出来也是我们想要的结果。
总结
1、CONCAT功能:将多个字符串连接成一个字符串。
2、语法:concat(str1, str2,…)
3、对比其它数据库中拼接字符串的用法Oracle字符串连接使用“||”进行字符串拼接,其使用方式和MSSQLServer中的加号“+”一样SELECT ‘房间号:’ || NO || ‘单价:’ || price FROM DUAL;当然,Oracle中对CONCAT()函数也是支持的
注意事项:
1、如果CONCAT中连接的值不是字符串,Oracle会尝试将其转换为字符串
2、与MYSQL的CONCAT()函数不同,Oracle的CONCAT()函数只支持两个参数,不支持两个以上字符串的拼接
3、Oracle中要拼接两个以上的参数,还是得用“||” 或者可以使用多个CONCAT()函数嵌套使用
例如:
SELECT CONCAT(CONCAT(CONCAT('CSDN:',NO),'测试一下:'),price) FROM DUAL;
边栏推荐
- Declaration and definition of template class
- Common PostgreSQL data operation notes (updated from time to time)
- 拥抱声明式UI
- The n-beats model was released in 2020 and is 3% better than the winner of the M4 competition!
- Tidb performance optimization overview
- 项目组暑假总结02
- 加密和解密
- 三种高并发方式实现i++
- 删除快照出现:删除快照时出错: 字典问题
- PingCAP Clinic 数据采集说明
猜你喜欢

mysql优化

邮箱发送邮件(包含附件,网易、QQ)

Wechat applet source code of high imitation Netease cloud music UI

简洁UI好玩的文字转换emoji表情微信小程序支持句子词语转换_源码

ThinkPHP official website tutorial

Problems encountered by Sphinx

TCP/IP 协议

【TA-霜狼_may-《百人计划》】图形2.5 Bump Mapping
![[FPGA tutorial case 27] realize dual port RAM ping-pong structure through Verilog](/img/64/211c5a6d6e0a8701136fa969d6d9e4.png)
[FPGA tutorial case 27] realize dual port RAM ping-pong structure through Verilog

Blessing for the elderly popular short video wechat applet source code download support traffic master
随机推荐
项目组暑假总结01
Reproduction of XOR and encryption decryption
HighTec 新建 AURIX TC37X demo 工程
Mongo Db单机版的安装和快速使用
拥抱声明式UI
Summary of black screen problems in unity UMP packaging
Embrace declarative UI
负载均衡器ribbon实战
Exploration: pharmaceutical factory system network clock synchronization (NTP time synchronization server)
Hightec new aurix tc37x demo project
TCP/IP 协议
Using everything to clean up junk files
常用postgresql数据操作备忘(不定时更新)
EasyExcel简单使用
Demo analysis of sliding conflict external interception method
masm32写程序
Website online package APK system source code
高等数学笔记:复合函数的二阶导数与参数方程求解曲率
An easy-to-use network liar reporting system without encrypted version source code
Notes on Advanced Mathematics: second derivative of composite function and curvature of solving parametric equation