Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE TRIGGER trg_update_park_capacity before
- INSERT OR DELETE ON parkingslot
- FOR each ROW
- DECLARE
- eletric_cap park.eletric_capacity%TYPE;
- non_eletric_cap park.non_eletric_capacity%TYPE;
- pa park.id_park%TYPE;
- btype bicycletype.id_bicycle_type%TYPE;
- BEGIN
- IF inserting THEN
- pa :=:NEW.id_park;
- btype :=:NEW.id_bicycle_type;
- IF btype = 3 THEN
- SELECT eletric_capacity
- INTO eletric_cap
- FROM park
- WHERE id_park = pa;
- eletric_cap:= eletric_cap + 1;
- ELSE
- SELECT non_eletric_capacity
- INTO non_eletric_cap
- FROM park
- WHERE id_park = pa;
- non_eletric_cap:= non_eletric_cap + 1;
- END IF;
- ELSE
- pa :=:NEW.id_park;
- btype :=:NEW.id_bicycle_type;
- btype :=:NEW.id_bicycle_type;
- IF btype = 3 THEN
- SELECT eletric_capacity
- INTO eletric_cap
- FROM park
- WHERE id_park = pa;
- eletric_cap:= eletric_cap - 1;
- ELSE
- SELECT non_eletric_capacity
- INTO non_eletric_cap
- FROM park
- WHERE id_park = pa;
- non_eletric_cap:= non_eletric_cap - 1;
- END IF;
- END IF;
- UPDATE park
- SET eletric_capacity = eletric_cap, non_eletric_capacity = non_eletric_cap
- WHERE id_park = pa;
- END trg_update_park_capacity;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement