Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.04 KB | None | 0 0
  1. //  PAQUETE.
  2.  
  3. CREATE OR REPLACE PACKAGE paqejer4
  4.  
  5. IS
  6.  
  7.     v_linea_tren NUMBER(5);
  8.     v_linea_estacion NUMBER(5);
  9.  
  10. END paqejer4;
  11. /
  12.  
  13. //  TRIGGER 1.
  14.  
  15.  
  16. CREATE OR REPLACE TRIGGER ejer4_1
  17.  
  18. before INSERT OR DELETE ON tren
  19.  
  20. FOR each ROW
  21.  
  22. BEGIN
  23.  
  24.     SELECT COUNT(*) INTO paqejer4.v_linea_estacion FROM linea_estacion WHERE linea = :NEW.linea;
  25.     SELECT COUNT(*) INTO paqejer4.v_linea_tren FROM tren WHERE linea = :NEW.linea;
  26.        
  27. END;
  28. /
  29.  
  30.  
  31. //  TRIGGER 2.
  32.  
  33. CREATE OR REPLACE TRIGGER ejer4_2
  34.  
  35. before INSERT OR DELETE ON tren
  36.  
  37. FOR each ROW
  38.  
  39. BEGIN
  40.  
  41.         IF inserting THEN
  42.        
  43.             IF (paqejer4.v_linea_tren > (paqejer4.v_linea_estacion*2)) THEN
  44.        
  45.                 raise_application_error(-20500,'Imposible insertar el tren. La línea no soporta más trenes.');
  46.        
  47.             END IF;
  48.        
  49.         END IF;
  50.        
  51.         IF deleting THEN
  52.                    
  53.             IF (paqejer4.v_linea_tren < paqejer4.v_linea_estacion) THEN
  54.        
  55.                 raise_application_error(-20500,'Imposible Borrar el tren. No puede haber menos trenes que estaciones.');
  56.        
  57.             END IF;
  58.                
  59.         END IF;
  60.            
  61.    
  62. END;
  63. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement