Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: LOOP question

Re: LOOP question

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Wed, 15 Sep 1999 16:39:33 -0400
Message-ID: <VwPgNzLGZ+t4lUPk2+qn08=5FNqq@4ax.com>


A copy of this was sent to iancrozier_at_aol.com (Iancrozier) (if that email address didn't require changing) On 15 Sep 1999 20:10:14 GMT, you wrote:

>I have code something like:
>DECLARE
>
>v_column number;
>
>CURSOR a IS SELECT column FROM table;
>
>BEGIN
>
>OPEN a;
>
>LOOP
>
>FETCH a INTO v_column;
>
>mesg := (RPAD(vcolumn,12));
>
>UTL_FILE.PUTF(file_name,'%s\n',mesg);
>
>UTL_FILE.PUT_LINE(file_name,' . ');
>
>UTL_FILE.FFLUSH(file_name);
>
>EXIT WHEN A%NOTFOUND;
>
>END LOOP;
>
>END;
>
>-- End of code
>
>When I look into file_name, the last row is always in there TWICE!
>
>What am I doing wrong? TIA

fetch a into v_column;
EXIT WHEN A%NOTFOUND;

put the exit when not found right after the fetch -- else you see that last record 2 times.

>
>Ian Crozier

--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Wed Sep 15 1999 - 15:39:33 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US