1->Query to find 2nd highest salary of an employee?
SELECT max(salary) FROM EMPLOYEES WHERE salary IN (SELECT salary FROM EMPLOYEEs MINUS SELECT max(salary) FROM EMPLOYEES);
2->Write a trigger to update Emp table such that, If an updation is done in Dep table then salary of all employees of that department should be incremented by some amount (updation)
Assuming Table name are Dept and Emp, trigger can be written as –
CREATE OR REPLACE TRIGGER update_trig AFTER UPDATE ON Dept FOR EACH ROW DECLARE CURSOR emp_cur IS SELECT * FROM Emp; BEGIN FOR i IN emp_cur LOOP IF i.dept_no = :NEW.dept_no THEN DBMS_OUTPUT.PUT_LINE(i.emp_no); -- for printing those UPDATE Emp -- emp number which are SET sal = i.sal + 100 -- updated WHERE emp_no = i.emp_no; END IF; END LOOP; END;
xxxxxxxxxxxxxx
No comments:
Post a Comment