sql - What do these trigger errors mean -
hey guys earlier. have ran new problem. few steps later in homework needed add additional part trigger. trigger needs subtract 1 number of copies. when number of copies hits 0 should display unavailable. have been trying last few hours figure out , came with. or suggestions appreciated!!
create or replace trigger unavailable_rule before insert on transaction each row begin if :new.date_rented_out not null , :new.date_returned null , num_copies=1 update video set num_copies = num_copies - 1, status = 'unavailable' vid_num = :new.vid_num; else num_copies = num_copies - 1; end if; end; / show errors; 6/4 pl/sql: sql statement ignored 7/15 pl/sql: ora-00971: missing set keyword 13/13 pls-00103: encountered symbol "=" when expecting 1 of f ollowing: := . ( @ % ; 14/2 pls-00103: encountered symbol "end"
your update
statement misformed. instead of:
update video num_copies = num_copies -1 set status = 'unavailable' vid_num = :new.vid_num;
assign num_copies
in set
:
update video set num_copies = num_copies - 1, status = 'unavailable' vid_num = :new.vid_num;
edit:
your if
statement can replaced with:
update video set num_copies = num_copies - 1, status = (case when :new.date_rented_out not null , :new.date_returned null , num_copies = 1 'unavailable' else status end) vid_num = :new.vid_num;
Comments
Post a Comment