Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: PLS/SQL: OK to use EXIT in a cursor FOR LOOP ??
In article <7kb90d$oad$1_at_nntp.csufresno.edu>, Steve Cosner
<stevec_at_zimmer.csufresno.edu> writes
[snip]
>
>Using a cursor FOR loop, and also erroneously defined cursor record is
>a HUGE pitfall for inexperienced programmers. The following has
>caused several of my associates hours and days of time wasted hunting
>down bugs:
>
>CURSOR my_csr IS
> SELECT a, b, C FROM my_table ORDER BY d;
>v_data my_csr%rowtype;
>
>FOR v_data IN my_cursor LOOP
> -- do some work
>END LOOP;
>If v_data.a = xxx then
> -- do some more work
>
>The above compiles just fine in PL/SQL, but it will NEVER work!
Poor old associates! I suppose that I don't fall for that as I never declare cursor records, as I always use cursor FOR loops (even when I only expect one value to be returned).
[snip]
>Raising exceptions or using many exit statements is the same as using
>Go_To's. In my opinion, that is poor programming practice.
>
Hm... I tend to agree, I usually use an exception when something invalid has occurred for which there is no sensible way for the procedure to handle. It seems neater than using a set of IF-THEN-ELSE statements.
Andy
--
Andy Hardy. PGP key available on request