Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.11 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.     SELECT eletric_capacity
  12.     INTO eletric_cap
  13.     FROM park
  14.     WHERE id_park = pa;
  15.     SELECT non_eletric_capacity
  16.     INTO non_eletric_cap
  17.     FROM park
  18.     WHERE id_park = pa;
  19.     IF inserting THEN              
  20.         btype :=:NEW.id_bicycle_type;        
  21.         IF btype = 1 THEN
  22.             eletric_cap:= eletric_cap + 1;
  23.         ELSE          
  24.             non_eletric_cap:= non_eletric_cap + 1;
  25.         END IF;
  26.     ELSE      
  27.         btype :=:NEW.id_bicycle_type;
  28.         IF btype = 1 THEN
  29.             eletric_cap:= eletric_cap - 1;
  30.         ELSE
  31.             non_eletric_cap:= non_eletric_cap - 1;
  32.         END IF;
  33.     END IF;
  34.     UPDATE park
  35.     SET eletric_capacity = eletric_cap, non_eletric_capacity = non_eletric_cap
  36.     WHERE id_park = pa;
  37. END trg_update_park_capacity;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement