我想在 SQL Server 中复制以下代码。我环顾四周,似乎唯一的选择是只使用直线光标,但有没有更好的方法:
DECLARE
CURSOR cursor1 IS
SELECT *
FROM table1;
TYPE cursor_aat IS TABLE OF cursor1%ROWTYPE;
l_cursor cursor_aat;
BEGIN
OPEN cursor1;
LOOP
FETCH cursor1
BULK COLLECT INTO l_cursor LIMIT 200;
FOR INDX IN 1 .. l_cursor.COUNT LOOP
IF (CheckSomeData() = 0) THEN
INSERT INTO new_table
(col1, col2)
values
(l_cursor(INDX).col1, l_cursor(INDX).col2);
INSERT INTO new_table2
...
end if
END LOOP;
EXIT WHEN l_cursor.COUNT < 200;
...