Insert value in while loop : While Loop « PL SQL « Oracle PL / SQL






Insert value in while loop

    
SQL>
SQL> create table supplier(
  2          supplier_no             integer           primary key
  3          ,supplier_name          varchar2(50)
  4          ,address                varchar(30)
  5          ,city                   varchar(20)
  6          ,state                  varchar2(2)
  7          ,area_code              varchar2(3)
  8          ,phone                  varchar2(8)
  9  );

Table created.

SQL>
SQL>
SQL> declare
  2     v_ctr   number := 2 ;
  3     v_prod_ctr number := 3 ;
  4     v_loop  number := 1;
  5
  6     v_curr_supplier supplier.supplier_no%TYPE ;
  7  begin
  8     WHILE v_loop <= v_ctr LOOP
  9             INSERT INTO supplier (SUPPLIER_NO, SUPPLIER_NAME)VALUES (v_loop+999, '#'||v_loop);
 10             v_loop := v_loop + 1 ;
 11     END LOOP;
 12     COMMIT;
 13  end;
 14  /

PL/SQL procedure successfully completed.

SQL>
SQL> select * from supplier;
SUPPLIER_NO SUPPLIER_NAME                                      ADDRESS                        CITY         ST ARE PHONE
----------- -------------------------------------------------- ------------------------------ -------------------- -- --- --------
       1000 #1
       1001 #2

2 rows selected.

SQL>
SQL> drop table supplier;

Table dropped.

SQL>
SQL> --

   
    
    
  








Related examples in the same category

1.Put two statement in while loop
2.Example of a WHILE loop that never executes
3.Corrected WHILE loop that executes
4.While Loop with condition
5.Change while loop counter
6.While loop with complex conditions
7.Do calculation with while loop counter
8.Call EXIT to jump out of a while loop
9.Use EXIT WHEN to exit a while loop
10.WHILE..LOOP, Cursor Loop
11.WHILE Loop: This condition will evaluate to NULL, since v_Counter is initialized to NULL by default
12.WHILE Loop: Test the loop counter before each loop iteration to insure that it is still less than 50
13.WHILE Loop
14.This script demonstrates variable visibility
15.The WHILE loop uses a loop index value as its gate on entry criterion:
16.While loop and number counter