【问题标题】:Warning: Trigger created with compilation error警告:使用编译错误创建触发器
【发布时间】:2020-10-06 19:57:10
【问题描述】:

我有两张表,seat_allocation 和 program_code。我想创建一个触发器来检查座位分配中的条目数是否等于该 prog_code(programm_code 表中的列)的 max_seats(programm_code 表中的列)。这是我的代码:

SQL> create or replace trigger seats_full
  2  before insert on seat_allocation
  3  for each row
  4  declare
  5  cnt programme_code.max_seats%type;
  6  max programme_code.max_seats%type;
  7  begin
  8  select count(*) into cnt from seat_allocation where prog_code=(select prog_code from programme_code where prog_code = :NEW.prog_code);
  9  select max_seats into max from programme_code where prog_code=(select prog_code from programme_code where prog_code = :NEW.prog_code);
 10  if max=cnt then
 11  RAISE_APPLICATION_ERROR(-21000,'No vacant seats available');
 12  end if;
 13  end;
 14  /

它给出警告:使用编译错误创建的触发器。你能帮我找出问题所在吗?

【问题讨论】:

  • 一个有用的提示:如果你打算从命令行编译代码,在你编译一个对象之后,如果它有错误,你可以使用show errors;命令查看导致该对象的错误编译失败。

标签: oracle triggers warnings


【解决方案1】:

变量名可以是MAX,为同名函数保留。将其更改为例如v_max_seats.


除此之外,您似乎是从 seat_allocation 表(第 8 行)中选择的,而触发器在同一个表上插入时触发。这会导致 mutating table 错误,所以 - 你必须做点什么。如今,它是一个解决此问题的复合触发器。如果您的数据库版本不支持它,您将使用一个包。网上有例子。


另外,为什么要使用子查询?例如有什么问题

select max_seats into v_max_seats from programme_code where prog_code = :new.prog_code

【讨论】:

  • 哦,好的,谢谢,我会尝试一下。感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 2021-12-27
  • 2019-07-12
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
  • 2012-01-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多