0% found this document useful (0 votes)
4 views

db6

Uploaded by

surajs300303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

db6

Uploaded by

surajs300303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

OUTPUT:

mysql> use Suraj;

Reading table information for completion of table and column


names
You can turn off this feature to get a quicker startup with -A
Database changed

mysql> create table o_rollcall(roll_no int,name varchar(20),address


varchar(20));

Query OK, 0 rows affected (0.28 sec)

mysql> create table n_rollcall(roll_no int,namevarchar(20),address


varchar(20));

Query OK, 0 rows affected (0.27 sec)

mysql> insert into o_rollcall values('1','Ani','Nandura'); Query OK, 1 row affected


(0.05 sec)

mysql> insert into o_rollcall values('2','Sam','MP');

Query OK, 1 row affected (0.06 sec)

mysql> insert into o_rollcall values('3','Siddhi','Nsk');

Query OK, 1 row affected (0.05 sec)

mysql> insert into o_rollcall values('4','Tejas','Dhule');

Query OK, 1 row affected (0.05 sec)

mysql> insert into o_rollcall values('5','Suraj','Satara');

Query OK, 1 row affected (0.04 sec)


mysql> delimiter //
mysql> create procedure p3(in r1 int)
-> begin
-> declare r2 int;
-> declare exit_loop boolean;
-> declare c1 cursor for select roll_no from o_rollcall
where roll_no>r1;
-> declare continue handler for not found set exit_loop=true;
-> open c1;
-> e_loop:loop
-> fetch c1 into r2;
-> if not exists(select * from n_rollcall where roll_no=r2)
-> then
-> insert into n_rollcall select * from o_rollcall where
roll_no=r2;
-> end if;
-> if exit_loop
-> then
-> close c1;
-> leave e_loop;
-> end if;
-> end loop e_loop;-> end
-> //

Query OK, 0 rows affected (0.00 sec)

mysql> call p3(3);


-> //
Query OK, 0 rows affected (0.10 sec)

mysql> select * from n_rollcall;


-> //
+ + + +

| roll_no | name
| address |
+ + + +
| 4 | Tejas | Dhule |
| 5 | Suraj |
| Satara
+ + + +
2 rows in set (0.00 sec)

mysql> call p3(0);


-> //

Query OK, 0 rows affected (0.22 sec)

mysql> select * from n_rollcall;


-> //
+ + + +
| roll_no | name
| address |
+ + + +
| 4 | Tejas | Dhule |
| 5 | Suraj | Satara |
| 1 | Ani | Nandura |
| 2 | Sam | MP |
| 3 | Siddhi | Nsk |+---------+---------+---------+
5 rows in set (0.00 sec)

mysql> insert into o_rollcall values('6','Patel','Kolhapur');


-> //

Query OK, 1 row affected (0.04 sec)

mysql> call p3(4);


-> //

Query OK, 0 rows affected (0.05 sec)

mysql> select * from n_rollcall;


-> //
+ + + +
| roll_no | name
| address
|
+ + + +
| 4 | Tejas | Dhule |
| 5 | Suraj | Satara |
| 1 | Ani | Nandura |
| 2 | Sam | MP |
| 3 | Siddhi | Nsk |
| 6 | Patel | Kolhapur |
+ + + +
6 rows in set (0.00 sec)
mysql>

You might also like