Wednesday 13 March 2013

What is the difference between a reference cursor and normal cursor?

The difference between these two is:
1. Normal cursor is Static & Ref cursor is dynamic.
2. A cursor is once define its contents are fixed and can't be changed. In dynamic cursors the contents of cursor can be changed dynamically depending upon the situation.
3. A cursor can't be passed as parameter from subroutine to subroutine. Whereas ref cursor can be     passed as parameter to subprograms.
4. A ref cursor can be returned to the client machine. A cursor can't.
5. A cursor can be defined globally. A ref cursor can't.
6. There are two types of Ref cursors:
Week & strong cursor
Type ref_name is Ref cursor [return type]
[return type] means Rowtype
            if Return type is mentioned then it is Strong cursor else weak cursor
7. The Reference cursor does not support For Update clause.

Generally we use ref cursor when we need to return result set. In other cases it is advisable to use static cursor because they give better performance.

1 comment: