Reading through the comments:
task given to me was :- "insert 10 records into a table using loop -
pl/sql"
and
so if there were 5 columns in a table, do i have to use 50 variables
for insertion ?
Answer to your above question is NO if you want the same set of records
to be inserted to your table 10 times. Below is the way you can do it. When you execute the block, it will ask you to promt value for 5 columns and accordingly it would insert 10 set of records with the same value to the table. See below.
SQL> DECLARE
num1 NUMBER (10) := &num1;
num2 NUMBER (10) := &num2;
num3 NUMBER (10) := &num3;
num4 NUMBER (10) := &num4;
num5 NUMBER (10) := &num5;
BEGIN
FOR i IN 1 .. 10
LOOP
INSERT INTO TAB (col1,
col2,
col3,
col4,
col5)
VALUES (num1,
num2,
num3,
num4,
num5);
END LOOP;
COMMIT;
END;
/
Enter value for num1: 1
old 2: num1 NUMBER (10) := &num1;
new 2: num1 NUMBER (10) := 1;
Enter value for num2: 2
old 3: num2 NUMBER (10) := &num2;
new 3: num2 NUMBER (10) := 2;
Enter value for num3: 3
old 4: num3 NUMBER (10) := &num3;
new 4: num3 NUMBER (10) := 3;
Enter value for num4: 4
old 5: num4 NUMBER (10) := &num4;
new 5: num4 NUMBER (10) := 4;
Enter value for num5: 5
old 6: num5 NUMBER (10) := &num5;
new 6: num5 NUMBER (10) := 5;
PL/SQL procedure successfully completed.
OUTPUT:
SQL> select * from tab;
COL1 COL2 COL3 COL4 COL5
---------- ---------- ---------- ---------- ----------
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
10 rows selected.