我处于需要将逗号分隔的项目 ID 从存储过程传递给函数的情况
存储过程是
CREATE PROCEDURE `spGetData`(
)
BEGIN
SET SESSION group_concat_max_len = 10000000;
set @leadProjectIDs = (SELECT distinct cast(group_concat(ProjectID separator ',')
as char(10000000))
from
project pr where Status = 2);
select fnCount(@leadProjectIDs) as Count;
END
功能是
CREATE FUNCTION `fnCount`(
_projectIds varchar(800)
) RETURNS decimal(10,2)
Begin
Set @LeadsCount = (Select count(*) from project where projectid in(_projectIds));
return @LeadsCount;
END
但上面的函数不返回任何计数。
我这里提到的 SP 和 Function 只是一个例子,我使用 Function 来获取数据,因为它有更多的条件和 join 然后在这里提到。
所以只想知道,我怎样才能传递像 1,2,3,4 这样的 projectid 并从 MYSQL 中的函数获取结果。