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 || ',%';
相关推荐
恣艺15 分钟前
Redis列表(List):实现队列/栈的利器,底层原理与实战
数据库·redis·list
秋难降39 分钟前
零基础学习SQL(十一):SQL 索引结构|从 B+Tree 到 Hash,面试常问的 “为啥选 B+Tree” 有答案了
数据库·后端·mysql
代码的余温1 小时前
Linux内核调优实战指南
linux·服务器·数据库
almighty271 小时前
C# DataGridView表头自定义设置全攻略
数据库·c#·winform·datagridview·自定义表头
ljh5746491191 小时前
mysql 必须在逗号分隔字符串和JSON字段之间二选一,怎么选
数据库·mysql·json
论迹2 小时前
【Redis】-- 持久化
数据库·redis·缓存
getdu2 小时前
Redis面试相关
数据库·redis·面试
TDengine (老段)2 小时前
TDengine 选择函数 TOP() 用户手册
大数据·数据库·物联网·时序数据库·iot·tdengine·涛思数据
m0_694845572 小时前
教你使用服务器如何搭建数据库
linux·运维·服务器·数据库·云计算
gamers2 小时前
rock linux 9 安装mysql 5.7.44
linux·mysql·adb