Home » SQL & PL/SQL » SQL & PL/SQL » Nested Loop Behaves Surprisingly
Nested Loop Behaves Surprisingly [message #39402] Mon, 15 July 2002 06:45 Go to next message
Jingkun Zhu
Messages: 5
Registered: July 2002
Junior Member
Hi,
I am writing a program that has two cursor loops like the following:

For a in cursor_a loop
statement1;
for b in cursor_b loop
statement 2;
end loop;
statement3;
end loop;

When cursor A holds 6 records and Cursor B holds 2 records, I expect statement 2 to be executed 12 times. Yet it was executed only 8 times. ( statement 2 was executed for only the first 2 records in cursor A).

When cursor A holds 6 records and cursor B holds 3, statement 2 was executed 12 times ( it was executed only for the first 3 records in cursor A), while I expected statement 2 to be executed 18 times ( 3 times for each record in cursor A).

What's wrong with my expectation?

Jingkun
Re: Nested Loop Behaves Surprisingly [message #39404 is a reply to message #39402] Mon, 15 July 2002 08:47 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Well, all things being equal, the loops will execute a * b rows.

Is cursor b dependent on data in cursor a? Is there some row in 'a' that would cause 'b' to return no rows?

Can you show some or all of your code so we can get a better idea of what might be happening here?
Previous Topic: Cursors
Next Topic: Showing a company hierachy with SQL
Goto Forum:
  


Current Time: Tue Apr 16 05:02:48 CDT 2024