Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Cursors vs Standard Cursors - speed issue 1

Status
Not open for further replies.

Spikmeister

Programmer
Jul 30, 2003
15
GB
I have two procedures that do identical things, one uses a Standard cursor that it loops through:
Code:
CURSOR Cursor_SP IS		
  SELECT ID, CCT_ID
  FROM SP_2
  WHERE Inserted_By = 'I';

BEGIN

  FOR List_SP IN Cursor_SP LOOP

    (Lots of data crunching with other tables)

  END LOOP;

END;

The other uses a dynamic one which it fetches into variables and then loops through:
Code:
sql_Statement VARCHAR2 (2000);
strid NUMBER;
strcctid VARCHAR2 (255);

BEGIN
  sql_Statement := 'SELECT ID, CCT_ID FROM SP_2 WHERE Inserted_By = ''I'' ';

  OPEN Sp_Cursor FOR sql_Statement;
    LOOP
		
      FETCH Spares_Cursor 
        INTO strid,
        strcctid;
      EXIT WHEN Spares_Cursor%NOTFOUND;

      (Same data cruching as other procedure)

    END LOOP;
  CLOSE Sp_Cursor;
END;

Is there any reason why the procedure with the Standard cursor takes half the time to run through that the one with the dynamic cursor does...???
 
Sure, because dynamic cursor should be parsed during runtime.

Regards, Dima
 
Please elaborate, I thought it was parsed during runtime...???
 
That's true for dynamic cursors; standard ones are parsed during compile time.

Regards, Dima
 
I'd suggest you to read about DBMS_SQL package to understand it more clear. Then just assume, that somebody kindly replaced a set of commonly used calls to this package to provide shorter notation.

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top