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 || ',%';
相关推荐
sky_81061320 小时前
Oracle ERP 各模块业务管理功能及底层表说明
数据库·oracle
YMatrix 官方技术社区21 小时前
CittaBase vs. Neo4j :原生图性能实测与混合检索实践
数据库·功能测试·ymatrix
闲猫1 天前
LangChain / Integrations / Integrations by component / Tool
java·数据库·langchain
xqqxqxxq1 天前
SQL 连接查询技术笔记
数据库·笔记·sql
Databend1 天前
从万亿级大模型到全线应用:Databend Cloud 助力头部 AI 企业构建全链路 Trace 数据管道
大数据·数据库·sql
MC皮蛋侠客1 天前
SQLAlchemy 系列(十一):从 1.x 到 2.x——渐进迁移与数据访问层治理
数据库·python
1001101_QIA1 天前
工控机网络配置
开发语言·数据库·php
ClouGence1 天前
加一张临时表,OceanBase Oracle 写入居然快了 30 倍!
数据库·sql·oracle
tju23331 天前
信创产业二十年:国产基础软件走到哪一步了?
数据库·gitee