Dbms Practical 7
Dbms Practical 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:
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
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> 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);