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

Dbms Practical 7

Uploaded by

janhaviraikar007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Dbms Practical 7

Uploaded by

janhaviraikar007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Zeal College of Engineering and Research

Subject: Database Management System Lab

Name: Janhavi Rahul Raikar


Roll No: T213011
Div: C
Batch: C1
Group A: Practical No. 7

PROBLEM STATEMENT:
Write a PL/SQL block of code using parameterized Cursor that will merge the data available
in the newly created table N_RollCall with the data available in the table O_RollCall. If the
data in the first table already exist in the second table then that data should be skipped.

CODE:

d-comp-dbms-17@dcompdbms17-OptiPlex-3070:~$ sudo mysql;


[sudo] password for d-comp-dbms-17:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.39-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use studcourse;


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 n_rollcall(roll_no int,name varchar(90),address varchar(90));
Query OK, 0 rows affected (1.24 sec)

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


Query OK, 0 rows affected (0.53 sec)

mysql> desc n_rollcall;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| roll_no | int | YES | | NULL | |
| name | varchar(90) | YES | | NULL | |
| address | varchar(90) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> desc o_rollcall;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| roll_no | int | YES | | NULL | |
| name | varchar(90) | YES | | NULL | |
| address | varchar(90) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> insert into n_rollcall values(1,"rushikesh","pune"),(2,"krishna","nagpur"),
(3,"imam","baramati"),(4,"swapnil","pimpri"),(5,"amit","katraj");
Query OK, 5 rows affected (0.11 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> insert into o_rollcall values(6,"janhavi","pune"),(2,"krishna","nagpur"),(7,"sai","katraj"),


(4,"swapnil","pimpri"),(8,"om","katraj");
Query OK, 5 rows affected (0.12 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> select * from n_rollcall;


+---------+-----------+----------+
| roll_no | name | address |
+---------+-----------+----------+
| 1 | rushikesh | pune |
| 2 | krishna | nagpur |
| 3 | imam | baramati |
| 4 | swapnil | pimpri |
| 5 | amit | katraj |
+---------+-----------+----------+
5 rows in set (0.00 sec)

mysql> select * from o_rollcall;


+---------+---------+---------+
| roll_no | name | address |
+---------+---------+---------+
| 6 | janhavi | pune |
| 2 | krishna | nagpur |
| 7 | sai | katraj |
| 4 | swapnil | pimpri |
| 8 | om | katraj |
+---------+---------+---------+
5 rows in set (0.00 sec)

mysql> delimiter //
mysql> create procedure n1(in rno1 int)
-> begin
-> declare rno2 int;
-> declare exit_cond boolean;
-> declare c1 cursor for select roll_no from o_rollcall where roll_no=rno1;
-> declare continue handler for not found set exit_cond=TRUE;
-> open c1;
-> l1:loop
-> fetch c1 into rno2;
-> if not exists(select * from n_rollcall where roll_no=rno2)
-> then
-> insert into n_rollcall select * from o_rollcall where roll_no=rno2;
-> end if;
-> if exit_cond then
-> close c1;
-> leave l1;
-> end if;
-> end loop l1;
-> end
-> //
Query OK, 0 rows affected (0.19 sec)

mysql> delimiter ;
mysql> call n1(5);

mysql> call n1(6);


Query OK, 0 rows affected (0.10 sec)

mysql> select * from n_rollcall;


+---------+-----------+----------+
| roll_no | name | address |
+---------+-----------+----------+
| 1 | rushikesh | pune |
| 2 | krishna | nagpur |
| 3 | imam | baramati |
| 4 | swapnil | pimpri |
| 5 | amit | katraj |
| 6 | janhavi | pune |
+---------+-----------+----------+
6 rows in set (0.00 sec)

mysql> call n1(7);


Query OK, 0 rows affected (0.12 sec)

mysql> call n1(7);


Query OK, 0 rows affected (0.01 sec)

mysql> call n1(8);


Query OK, 0 rows affected (0.09 sec)

mysql> select * from n_rollcall;


+---------+-----------+----------+
| roll_no | name | address |
+---------+-----------+----------+
| 1 | rushikesh | pune |
| 2 | krishna | nagpur |
| 3 | imam | baramati |
| 4 | swapnil | pimpri |
| 5 | amit | katraj |
| 6 | janhavi | pune |
| 7 | sai | katraj |
| 8 | om | katraj |
+---------+-----------+----------+
8 rows in set (0.00 sec)
OUTPUT:

You might also like