In Oracle, there are only 2 types of cursor i.e. Implicit and Explicit cursor. Which is easy to understand. But, in SQL Server there are 4 Cursor AFAIK i.e. Static,Dynamic,Forward Only and Scroll. Which I feel very difficult to understand.
I got code for forward only,dynamic and static cursor and except cursor declaration everything is same. So, my question is, how they are different ?
declare @id int
declare @ename varchar(20)
declare @cnt int
declare cur_emp cursor forward_only for select sid,ename from emp
open cur_emp
set @cnt=@@cursor_rows
while @cnt>0
begin
set @cnt=@cnt-1
print @cnt
fetch next from cur_emp into @id,@ename
print cast(@id as varchar)+' '+@ename
end
close cur_emp
deallocate cur_emp
Even, above code doesn't showing any output except Command(s) completed successfully.. But, when I change the cursor declaration to static. Then, it is showing some output. Please help me.