mysql 存储过程 通过传入ids[]数组参数, 实现批量删除数据!
求大神解答。 存储过程,接收的参数为,保存多个id的字符串数组 ,以实现批量删除的 ,这样的存储过程怎么写?
纯粹精神恋爱
9 years, 7 months ago
Answers
create procedure sp_split_string
(
@string
NVARCHAR(4000)
)
AS
BEGIN
DECLARE @object_id nvarchar(500)
DECLARE @i INT
DECLARE
@len
INT
print
@string
IF (
@string
IS NULL) OR (LTRIM(@string) = '')
RETURN
WHILE CHARINDEX(',',@string) > 0
BEGIN
SET @len = LEN(@string)
SET @i = CHARINDEX(',', @string)
SET @object_id = LEFT(@string, @i-1)
INSERT INTO a (id) VALUES (@object_id)--少做修改,改成需要的sql语句即可
SET @string = RIGHT(@string, @len - @i)
END
SET @object_id = @string
INSERT INTO a (id) VALUES (@object_id)--少做修改,改成需要的sql语句即可
END
go
--测试
-- select * from a
-- exec sp_split_string '102,103,105,106,107,108,200,500,306,408'
-- select * from a
s3mytao
answered 9 years, 7 months ago