Re: Help, Pls--How do I use dynamic varaibles within a loop?

From: Graham Miller <lgmiller_at_elmrd.u-net.com>
Date: Sun, 27 Jun 1999 12:42:43 GMT
Message-ID: <377a1b40.25277306_at_news.u-net.com>


Hi,

Substitution variable are a feature of SQL*Plus. It parses the variables in the script and gets the required values.

SQL*Plus only passes down the script once! You will have to call your script 3 / (n) times to do what you want, insert ONE row each time.

graham

On Thu, 24 Jun 1999 22:29:31 -0700, Les <exlibris_at_sprynet.com> wrote:

>
>I am trying to input three records into a table
>using a loop, but it does not work the way I
>envisioned it. I get no chance to input 2nd and
>third name. Any suggestions?
>
>
>SQL> declare
> 2 max_rec int := 3;
> 3 i int := 1;
> 4 BEGIN
> 5 for i in 1..max_rec loop
> 6 insert into cust
> 7 (cno, name)
> 8 values
> 9 (&no, '&namee');
> 10 end loop;
> 11 end;
> 12 /
>Enter value for no: 10
>Enter value for namee: Bubba
>old 9: (&no, '&namee');
>new 9: (10, 'Bubba');
>
>PL/SQL procedure successfully completed.
>
>SQL> select * from cust;
>
> CNO NAME
>--------- ----------
> 1 Alan
> 2 Bill
> 3 Charles
> 10 Bubba
> 10 Bubba
> 10 Bubba
>
>6 rows selected.
>
>SQL>
>
>As you see, the loop executed three times, inserting
>identical record. Now what?
>
Received on Sun Jun 27 1999 - 14:42:43 CEST

Original text of this message