Sei sulla pagina 1di 5

1.

Write a PL/SQL Stored Procedure to list employee names whose salary is more than their Manager (to whom they report) salary. mysql> create procedure problem1() -> begin -> select e1.fname from employee e1,employee e2 where e1.superssn=e2.ssn AND e1.salary >2.salary; -> end; -> |

2. Write a PL/SQL Stored Procedure to update salary of all managers with 5% increment. Also record such updations in a log table with entries {empno, ename, old sal, new sal, date of updations}. mysql> create procedure p5() -> begin -> update employee set salary=(salary+salary*0.5) where ssn in(select mgrssn from department); -> end; -> | Query OK, 0 rows affected (0.04 sec)

mysql> create procedure p2() -> begin -> declare done int default false; -> declare no,sal int; -> declare name varchar(20); -> declare u_date date; -> declare c cursor for select ssn,fname,salary from employee; -> update employee set salary=(salary+salary*0.5) where ssn in(select mgrssn from department); -> open c; -> l:loop -> fetch c into no,sal,name; -> select no,name;

-> if done then -> leave l; -> end if; -> end loop; -> close c; -> end; -> | Query OK, 0 rows affected (0.00 sec)

3. Create a cursor to display the names of employees who works on all the projects controlled by department no. 5. mysql> create procedure prob3() -> begin -> declare done int default false; -> declare name varchar(20); -> declare c cursor for select fname from employee where ssn in(select essn from works_on where pno in(select pinteger from project where dnum=5)) and dno=5 ; -> open c; -> l:loop -> fetch c into name; -> select name; -> if done then -> leave l; -> end if; -> end loop; -> close c; -> end; -> |

Query OK, 0 rows affected (0.00 sec)

mysql> call prob3(); -> | +------+ | name | +------+ | JOHN | +------+ 1 row in set (0.00 sec)

+----------+ | name +----------+ | FRANKLIN | +----------+ 1 row in set (0.00 sec) |

+-------+ | name | +-------+ | JOYCE | +-------+ 1 row in set (0.01 sec)

+--------+ | name | +--------+ | RAMESH |

+--------+ 1 row in set (0.01 sec)

4. Create an update trigger which will not allow any changes in the value of the salary column in the employee table.

mysql> create trigger update_alert before update on employee for each row -> begin -> if(new.salary!=old.salary) then -> set new='you do not have access to update '; -> end if; -> end; -> | Query OK, 0 rows affected (0.10 sec)

mysql> update employee set salary=5000 where ssn=3344; -> | ERROR 1231 (42000): Variable 'new' can't be set to the value of 'you do not have access to update '

5.

Create an insert trigger which will not allow salary of an employee greater than 60000.

mysql> create trigger insert_alert before insert on employee for each row -> begin -> if new.salary > 60000 -> then -> set new=' price cannot to inserted '; -> end if; -> end; -> |

Query OK, 0 rows affected (0.13 sec)

mysql> insert into employee values('sai','m','pamidi',11111,'male',800000,22222, 89); -> | ERROR 1231 (42000): Variable 'new' can't be set to the value of ' price cannot t o inserted '

Potrebbero piacerti anche