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