Using Explicit Cursors  «Prev 

Closing a cursor in PL/SQL

Syntax and example for closing a cursor
cursor_name
Name of the cursor
pets
Name of the cursor

CLOSE_CURSOR

You can close an open cursor by executing the CLOSE_CURSOR procedure of the DBMS_SQL package. The example in the following listing, from the ANYSTRING procedure, shows that the
CLOSE_CURSOR procedure uses the cursor ID value as its sole input parameter:
DBMS_SQL.CLOSE_CURSOR(Cursor_Name);
Closing a cursor frees the memory used by the cursor and reduces the number of concurrently open cursors in your session.
Unless you need very detailed control over the steps involved in executing dynamic SQL, you should use the EXECUTE IMMEDIATE approach.

create or replace procedure ANYSTRING(String IN VARCHAR2) AS
Cursor_Name INTEGER;
Ret INTEGER;
BEGIN
Cursor_Name := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(Cursor_Name, String, dbms_sql.Native);
Ret := DBMS_SQL.EXECUTE(Cursor_Name);
DBMS_SQL.CLOSE_CURSOR(Cursor_Name);
END;