Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 0.96 KB | None | 0 0
  1. CREATE OR REPLACE TRIGGER trg_update_park_capacity before
  2. INSERT OR DELETE ON parkingslot
  3.     FOR each ROW
  4. DECLARE
  5.     eletric_cap   park.eletric_capacity%TYPE;
  6.     non_eletric_cap   park.non_eletric_capacity%TYPE;
  7.     pa park.id_park%TYPE;
  8.     btype bicycletype.id_bicycle_type%TYPE;
  9. BEGIN
  10.     pa :=:NEW.id_park;
  11.     eletric_cap := 0;
  12.     non_eletric_cap := 0;
  13.     IF inserting THEN              
  14.         btype :=:NEW.id_bicycle_type;        
  15.         IF btype = 1 THEN
  16.             eletric_cap:= 1;
  17.         ELSE          
  18.             non_eletric_cap:= 1;
  19.         END IF;
  20.     ELSE      
  21.         btype :=:NEW.id_bicycle_type;
  22.         IF btype = 1 THEN
  23.             eletric_cap:= - 1;
  24.         ELSE
  25.             non_eletric_cap:= - 1;
  26.         END IF;
  27.     END IF;
  28.     UPDATE park
  29.     SET eletric_capacity = eletric_capacity + eletric_cap, non_eletric_capacity = non_eletric_capacity + non_eletric_cap
  30.     WHERE id_park = pa;
  31. END trg_update_park_capacity;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement