MySQL/Oracle用逗号分割的id怎么实现in (逗号分割的id字符串)。find_in_set(`id`, ‘1,2,3‘) 函数,

1.MySQL

1.1.正确写法

sql 复制代码
select * from student where find_in_set(`s_id`, '1,2,3');  

1.2.错误示范

sql 复制代码
select * from student where find_in_set(`s_id`, '1,2 ,3');     -- 注意,中间不能有空格。1、3
select * from student where find_in_set(`s_id`, '1,2, 3');     -- 注意,中间不能有空格。1、2
select * from student where find_in_set(`s_id`, '1,2 , 3');    -- 注意,中间不能有空格。1

2.Oracle

2.1.方式一

sql 复制代码
select * 
from student 
where s_id in
	(
	select regexp_substr('1,2,3', '[^,]+', 1, level) as value
	from dual
	connect by regexp_substr('1,2,3', '[^,]+', 1, level) is not null
	);

2.2.方式二

sql 复制代码
-- 在Oracle SQL中,没有内置的FIND_IN_SET函数,但是你可以使用一些技巧来实现类似的功能。以下是一个示例:

SELECT *
FROM student
WHERE ',' || '1,2,3' || ',' LIKE '%,' || s_id || ',%';
相关推荐
傻啦嘿哟35 分钟前
Python安全实践:使用加密的XML配置文件保护敏感数据
数据库·oracle
一 乐43 分钟前
人事管理系统|基于Springboot+vue的企业人力资源管理系统设计与实现(源码+数据库+文档)
java·前端·javascript·数据库·vue.js·spring boot·后端
SelectDB1 小时前
浙江头部城商行:每日 700 万查询、秒级响应,Apache Doris 查算分离架构破局资源冲突
数据库·后端·apache
猫猫虫。1 小时前
解决数据库慢查询
数据库
zyxqyy&∞1 小时前
mysql代码小练-3
数据库·mysql
dzl843941 小时前
HikariCP 数据库连接池配置
数据库
万邦科技Lafite1 小时前
一键获取淘宝关键词商品信息指南
开发语言·数据库·python·商品信息·开放api·电商开放平台
程序猿20232 小时前
MySQL的索引
数据库·mysql
m0_692540072 小时前
数据库表设计规范
数据库·oracle
Coder_Boy_2 小时前
【人工智能应用技术】-基础实战-环境搭建(基于springAI+通义千问)(二)
数据库·人工智能