Saturday, 20 September 2014

FOR i IN SELECT oracle LOOP

Create tables

create table table1(rollno number,name VARCHAR2(15));

table TABLE1 created.

create table table2(myno number,name VARCHAR2(20));

table TABLE2 created.

Insert values into table1

insert all into table1(rollno,name) values (111,'luke')
           into table1(rollno,name) values (112,'owen')
           into table1(rollno,name) values (113,'aria')
           into table1(rollno,name) values (114,'samuel')
           into table1(rollno,name) values (115,'gabrial')

SELECT * FROM dual;

5 rows inserted.

Code

BEGIN
for i in (SELECT ROLLNO,NAME FROM TABLE1)
LOOP
INSERT into TABLE2(MYNO,NAME) values(i.rollno,i.name);
End Loop;
End;

anonymous block completed.

Select table2

SELECT * FROM table2;

Output

111 luke
112 owen
113 aria
114 samuel

115 gabrial

No comments:

Post a Comment