获取错误的绑定变量" old.seatsremain"和" new.seatsremain"。如果座位可用于特定产品,尝试启用此触发器会自动减少产品的席位数。我是否必须使用:在它前面声明所有变量????我的两张桌子是:
enrollments
{sid number,
offerno number;)
和
offering
{offerno number,
courseno varchar2(10),
instructor varchar2(10),
seatsremain number;}
更新的代码测试:好的,所以我合并了Fumble给我的编码,它清除了最初弹出的错误但是我测试了这个新代码,我仍然有一些剩余的错误,因为EXCEPTION子句,我不知道为什么,因为我仔细检查的语法应该是正确的。任何想法??
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;
/
此错误现在显示: PLS-00103:遇到符号" EXCEPTION"当期待一个 以下的: 如果loop mod null pragma,则开始case为goto声明end exit 使用时提高返回选择更新 << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe
PLS-00103:遇到符号"文件结束"什么时候期待 以下之一: 结束不是pragma最终可实例化的命令覆盖静态
答案 0 :(得分:1)
您正在使用除创建触发器之外的表中的相关名称。尝试将oldSeatsRemain和NewSeatsRemain声明为触发器中的变量。
试试这个(注意:此样本尚未执行)。它包括我在评论中描述的编辑。
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
/