Kimossab

ABD - Ficha 6

Nov 16th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.28 KB | None | 0 0
  1. /*1*/
  2. ALTER TABLE EMP ADD(divisa VARCHAR2(3) DEFAULT 'PTE');
  3. ALTER TABLE EMP ADD CHECK(divisa IN ('EUR','PTE'));
  4.  
  5. CREATE OR REPLACE TRIGGER divch
  6.   Before UPDATE OF Divisa ON Emp
  7.   FOR Each ROW
  8.  
  9. BEGIN
  10.   IF :NEW.divisa = 'EUR' THEN
  11.     :NEW.sal := :NEW.sal / 200.482;
  12.   ELSE
  13.     :NEW.sal := :NEW.sal * 200.482;
  14.   END IF;
  15. END;
  16.  
  17. UPDATE Emp SET divisa = 'EUR' WHERE empno = 1693;
  18. /*2*/
  19. CREATE OR REPLACE TRIGGER deptch
  20.   Before UPDATE OF deptno ON Emp
  21.   FOR Each ROW
  22.   WHEN (NEW.deptno <> old.deptno)
  23.  
  24. BEGIN
  25.   raise_application_error(-20600,'Não é permitod mudar de departamento');
  26. END;
  27.  
  28. UPDATE Emp SET deptno = 20 WHERE empno = 1693;
  29. DROP TRIGGER salch;
  30. /*3*/
  31. CREATE OR REPLACE TRIGGER salch
  32.   Before UPDATE OF sal ON Emp
  33.   FOR Each ROW
  34.  
  35. BEGIN
  36.   IF (:NEW.sal <= :old.sal) THEN
  37.     raise_application_error(-20600,'Não é permitod baixar o salario');
  38.   END IF;
  39. END;
  40.  
  41. UPDATE Emp SET sal = 100 WHERE empno = 1693;
  42. UPDATE Emp SET sal = 10 WHERE empno = 1693;
  43.  
  44. /*4*/
  45. CREATE OR REPLACE TRIGGER salch
  46.   Before UPDATE OR INSERT OR DELETE ON Emp
  47.   FOR Each ROW
  48.  
  49. DECLARE hora NUMBER(2);
  50.  
  51. BEGIN
  52.   SELECT (TO_NUMBER(TO_CHAR(SYSDATE,'HH24'))) INTO hora FROM dual;
  53.   IF hora < 8 OR hora > 19  THEN
  54.     raise_application_error(-20600,'Fora de Horas!!');
  55.   END IF;
  56. END;
Advertisement
Add Comment
Please, Sign In to add comment