下面是一个 SQL Server 存储过程。事务开始时有两个提交,如下所示。这是否有效(开始在 while 循环中,第一次提交在同一个 while 循环中,但第二次提交在第二次 while 循环中)?如果不是,那么解决方案可能是什么?
请帮忙。
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DELETE_COBOC_DATA')
DROP PROCEDURE DELETE_COBOC_DATA
GO
CREATE PROCEDURE DELETE_COBOC_DATA @ORGDN VARCHAR(100), @CHUNK VARCHAR(10)
AS
BEGIN
-- some code that executes before while
WHILE (@NUM_ROWS_TMPTRADMIN > 0)
BEGIN
BEGIN TRANSACTION
-- executes some code
COMMIT TRANSACTION
END
-- some more code
WHILE @NUM_ROWS_TMPDIR > 0
BEGIN
-- code code code
COMMIT TRANSACTION
-- code code code
END
-- some more code here as well
END
据我所知,这在 MySQL 中是允许的