我有一个 SQL 脚本,其中包含声明为的变量,DECLARE @@var_1 as bigint
并且它包含一个 while 循环,因为WHILE @@FETCH_STATUS
现在使用 NPoco 执行此类脚本会引发异常,Must declare the scalar variable "@FETCH_STATUS".
我该如何解决它?主要目的是在 SQL Server 和 ORACLE 中使用相同的脚本。
DECLARE @@LayerId bigint;
DECLARE @@DId as bigint;
DECLARE @@DataSegment as CURSOR;
DECLARE @@IterationNo as int;
IF OBJECT_ID(N'DataSegment') IS NOT NULL AND
OBJECT_ID(N'Layer') IS NOT NULL
BEGIN
SET @@IterationNo = 0;
SET @@DataSegment = CURSOR FORWARD_ONLY FOR
SELECT Id FROM DataSegment
OPEN @@DataSegment;
FETCH NEXT FROM @@DataSegment INTO @@DId
WHILE @@FETCH_STATUS = 0
BEGIN
SET @@IterationNo = @@IterationNo + 1;
SET @@LayerId = 9;
PRINT @@LayerId;
--Insert parent RouteVersion
INSERT INTO Layer Values(@@LayerId,'Migration',6,'Trace',
'Route','TEST', @@DId, NULL, @@LayerId, 9)
Print 'Iter is ' ;
Print @@IterationNo
--fetch next
FETCH NEXT FROM @@DataSegment INTO @@DId;
END
CLOSE @@DataSegment;
DEALLOCATE @@DataSegment;
END
提前致谢。