Can I reset cursor's position to the beginning?

前端 未结 4 2003
感动是毒
感动是毒 2020-12-29 22:27

As in the topic. Can I simply reset cursor\'s position to the beginning in Transact-SQL, so it can run again over the table? I want to reset it in the following context:

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 23:18

    Use cursor loops and its taken care of for you...

    cursor c_something IS
       select * from somewhere
    
    BEGIN
    
        for some_row in c_something LOOP
            -- do stuff with some_row.COLUMN;
        END LOOP; -- this closes the cursor for you when it has gone all the way through
    
        -- do other stuff
    
        for some_row in c_something LOOP -- opens the cursor again from the top
            -- do stuff with some_row.COLUMN;
        END LOOP;
    
    END;
    

提交回复
热议问题