?
Solved

How to rewind opened cursor in PL/SQL

Posted on 1997-12-10
1
Medium Priority
?
2,943 Views
Last Modified: 2008-02-01
Hi!

I'm writing procedure in PL/SQL for ORACLE 8.
I need to run the same SQL statment in a loop, in witch I reopen the
cursor everytime I get to the head of loop. The cursor parameters
doesn't change.

Is it possible to rewind opened cursor to save the time and don't
open the cursor for reading the database each time getting the head
of the loop after closing this cursor at the loop bottom ?

thanks.

    Alex Ziablitsev
0
Comment
Question by:alz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
leonidt earned 600 total points
ID: 1081117
Unforunately OPEN statement for cursor corresponds to the
PARSE, BIND and EXECUTE operations.
In your case you basically don't need to do PARSE and BIND
you just need to reexecute SQL stmt (probably because your
data in a table(s) have changed. If you really want to do it
everything in PL/SQL then  
my only suggestion is to use DBMS_SQL package which gives you
more flexibility. You put
DBMS_SQL.OPEN_CURSOR, DBMS_SQL.PARSE AND DBMS_SQL.DEFINE_COLUMN
outside the loop. If you bind any variable (or if in your
original program you had the parameterised cursor and the parameter changed in the loop) you put the
DBMS_SQL.BIND_VARIABLE inside the loop. You do
DBSM_SQL.EXECUTE inside the loop and then fetch the rows
from your cursor.

Basically the same schema is used when you are using
C/C++ or Visual Basic from the client.

You don't need to Open and Close the Cursor any more inside the loop.

From my experience there is very small overhead in comparison with the cursors.




0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question