我正在尝试将逗号分隔的电子邮件ID列表传递给@b.com,s @ b.com进入sql in子句是我的查询权请提供一些建议
SELECT * FROM service.cs_list_of_email_ids where Email in (
SELECT regexp_substr(:a@b.com,s@b.com,'[^,]+', 1, level) items
FROM dual
CONNECT BY regexp_substr(:a@b.com,s@b.com, '[^,]+', 1, level) is not null
);
答案 0 :(得分:0)
由于您没有提及是否使用Sql Server
,因此可以创建此函数以拆分逗号分隔的字符串
CREATE FUNCTION Split
(
@delimited nvarchar(max),
@delimiter nvarchar(100)
) RETURNS @t TABLE
(
-- Id column can be commented out, not required for sql splitting string
id int identity(1,1), -- I use this column for numbering splitted parts
val nvarchar(max)
)
AS
BEGIN
declare @xml xml
set @xml = N'<root><r>' + replace(@delimited,@delimiter,'</r><r>') + '</r></root>'
insert into @t(val)
select
r.value('.','varchar(max)') as item
from @xml.nodes('//root/r') as records(r)
RETURN
END
GO
然后将其称为
SELECT * FROM service.cs_list_of_email_ids where Email in
(SELECT val FROM dbo.split(@str,','))