Vous êtes sur la page 1sur 4

REF CURSORS

Strong REF Cursors


Weak REF Cursors
SYS REF Cursors
REF Cursor
• REF CURSOR is one of the most powerful, flexible, and scalable ways to return
query results from an Oracle Database to a client application
• Ref Cursor is oracle pl/SQL Data type.
• Ref Cursor is also referred as Cursor variable
• Cursor variables are pointers to result set
• Cursor can be attached to only one query at a time where as REF cursor can be
used to associate multiple queries at run time.
• REF CURSORs characteristics:
A REF CURSOR refers to a memory address on the database.
A REF CURSOR is not updatable.
A REF CURSOR is not backward scrollable. The data represented by the REF
CURSOR is accessed in a forward-only, serial manner. You cannot position a
record pointer inside the REF CURSOR to point to random records in the result
set.
A REF CURSOR is a PL/SQL data type. You create and return a REF CURSOR
inside a PL/SQL code block.
Ref Cursor & Static Cursor
• Difference Between Cursor and a REF cursor
• Technically, at the most basic level they are same.
• A normal pl/sql cursor is static where as REF cursors may be dynamically opened or opened based on logic
• Ref cursor can be returned values to a client where as cursor cannot be returned values to a client.
• Cursor can be global where as ref cursor cannot(you cannot define them outside of a procedure or function)
• Advantages
• 1. Ref Cursor it self is a data type and easy to declare
• 2. More flexible because it is not tied to a specific query
• 3. Easily pass as arguments from subroutine to subroutine.
• 4. Very handy in transferring data between multi-language application (ex:- Java and Oracle, Dot.net and Oracle,
Oracle Forms and Oracle). Since it is a pointer to the result set any client and server program can use the pointer to
access the data.
• 5. Cursor variables are bind variables
• Dis-advantages
• 1. Ref Cursors are not efficient as Static Cursor
• 2. Need additional code to print Ref Cursor values
• Ref cursors are not allow to use in packages directly.
• In general Ref Cursors are only be used when static cursor cannot do the work.
Ref Cursor types
• Strong Ref Cursor
• A Ref cursor which has return type is classified as Strong Ref cursor
• EX: TYPE t1 IS REF CURSOR RETURN emp%ROWTYPE;
• Weak Ref Cursor
• A Ref Cursor which has no return type is classified as weak Ref Cursor
• EX: TYPE t1 IS REF CURSOR;
• System Ref Cursor
• This is system defined Ref Cursor, also it is weak ref cursor.
• System ref cursor need not to declare explicitly
• EX: DECLARE
t1 SYS_REFCURSOR;