posted 12 years ago
In your inner loop on cursor d (you need to improve your naming conventions here), are you sure that the exit condition will always occur?
More generally, you would probably find it a lot easier to use a cursor FOR loop here. Here's a couple of examples based on your SQL:
No more Blub for me, thank you, Vicar.