Reputation: 31
getting a bad bind variable "old.seatsremain" and "new.seatsremain". Trying to make this trigger automatically decrease the number of seats for the offering if the seats are available for the particular offering. Do I have to declare all the variables with the : in front of it???? my two tables are:
enrollments
{sid number,
offerno number;)
and
offering
{offerno number,
courseno varchar2(10),
instructor varchar2(10),
seatsremain number;}
UPDATED CODE TESTING: OK so I incorporated the coding Fumble gave me and it cleared the errors for ones that originally popped up however I tested out this new code and I still have some remaining error because of the EXCEPTION clause which I have no idea why because the syntax I double checked should be right. any ideas??
create or replace trigger enroll_bef_ins_row
before insert on enrollments
for each row
declare
originstruct offering.instructor%type;
origcourseno offering.courseno%type;
original offering.seatsremain%type;
seatsremain_already_full exception;
begin
Select seatsremain, instructor, courseno into original, originstruct, origcourseno from offering where offerno= :new.offerno;
if original > 0 then
update offering set seatsremain= seatsremain - 1;
dbms_output.put_line ('Seats available in offering'||offerno||'have decreased from'||original|| 'to' ||(seatsremain));
else if original = 0 then
raise seatsremain_already_full;
dbms_output.put_line ('Offering'||offerno||'is already full!');
else
update offering set offerno = :old.offerno;
update offering set courseno = origcourseno;
update offering set instructor = originstruct;
update offering set seatsremain = original;
end if;
exception
when seatsremain_already_full then
raise_application_error (-20001, 'Cannot allow insertion');
commit;
end;
/
THIS ERROR SHOWS UP NOW: PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following: begin case declare end exit for goto if loop mod null pragma raise return select update while with << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: end not pragma final instantiable order overriding static
Upvotes: 1
Views: 135
Reputation: 441
You are using correlation names from a table other than the one your trigger is created for. Try declaring oldSeatsRemain and NewSeatsRemain as variables within your trigger.
Try this (note: this sample has not been executed). It includes the edits I described in my comments.
create or replace trigger enroll_bef_ins_row
before insert on enrollments
for each row
declare
offerrow offering%rowtype;
seatsremain_already_full exception;
pragma autonomus_transaction;
begin
Select seatsremain into offerrow from offering where offerno= :new.offerno;
if offerrow.seatsremain > 0 then
update offering set seatsremain= offerrow.seatsremain - 1;
dmbs_output.put_line ('Seats available in offering ' |offerno| ' have decreased from ' |offerrow.seatsremain| ' to ' |offerrow.seatsremain-1|);
else if original = 0 then
dbms_output.put_line ('Offering ' |offerno| ' is already full!');
raise seatsremain_already_full;
else
insert into offering
values(offering.offerno,offering.courseno,offering.instructor,offering.seatsremain);
end if;
commit;
exception
when seatsremain_already_full
raise_application_error (-20001, 'Cannot allow insertion');
end
/
Upvotes: 1