In PL / SQL, what's the difference between a cursor and a reference cursor?

To my knowledge, the cursor is used to process SQL statements in a private area, and we can use it further. The Ref cursor defines the cursor where it is needed. Please correct me if I am wrong.

+4
source share
2 answers

A cursor is really any SQL statement that runs DML (selects, inserts, updates, deletes) in your database.

The ref cursor is a pointer to the result set. This is usually used to open a query on a database server, and then leave it to the client to get the desired result. The ref cursor is also a cursor, although the term term cursor is usually used when discussing static SQL.

Link cursors are commonly used to modify the where clause based on user input. For example, this function either opens a query to the emp table or the dept table, depending on what the user has selected:

 create or replace function f (input in varchar2) return sys_refcursor as cur sys_refcursor; begin if input = 'EMP' then open cur for select * from emp; elsif input = 'DEPT' then open cur for select * from dept; end if; return cur; end; / 
+2
source

A static cursor is associated with a single SQL query. This is not flexible, therefore, for a dynamic cursor called a cursor cursor , the same cursor is used for different queries.

0
source

All Articles