SQL> create table table1(e number(5),f number(5));
Table created.
SQL> insert into table1 values(1,3);
1 row created.
SQL> insert into table1 values(2,4);
1 row created.
SQL> select * from table1;
E F
---------- ----------
1 3
2 4
SQL> declare
2 a number;
3 b number;
4 begin
5 select e,f into a,b from table1 where e>1;
6 insert into table1 values(b,a);
7 end;
8 /
PL/SQL procedure successfully completed.
SQL> select * from table1;
E F
---------- ----------
1 3
2 4
4 2
CONTROL FLOW IN PL/SQL:
IF:
SQL> declare
2 a number;
3 b number;
4 begin
5 select e,f into a,b from table1 where e>1;
6 if b=1 then
7 insert into table1 values(b,a);
8 else
9 insert into table1 values(b+10,a+10);
10 end if;
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> select * from table1;
E F
---------- ----------
1 3
2 4
14 12
LOOP:
SQL> declare
2 i number:=1;
3 begin
4 loop
5 insert into table1 values(i,i);
6 i:=i+1;
7 exit when i>=5;
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> select * from table1;
E F
---------- ----------
1 3
2 4
14 12
1 1
2 2
3 3
4 4
7 rows selected.