错误:超出了最大递归SQL级别数(50)

时间:2013-12-29 15:01:21

标签: sql oracle

我想强制执行诚信,以便一个人不能每天多次借书。表&触发器编译没有错误但是当你尝试插入时我得到了上述错误。我无法解决它。语法:

create or replace trigger chk_DateL
for insert or update on lending
COMPOUND TRIGGER
--declare
L_Date number(1);
avail varchar2(10);
subtype copy_booksRec is lending%ROWTYPE;
type copied_bks is table of copy_booksRec;
cbks copied_bks := copied_bks();

after each row is 
begin
  cbks.extend;
  cbks(cbks.last).cb_num := :new.cb_num;
  cbks(cbks.last).sb_num := :new.sb_num;
end after each row;

after statement is
begin
  for i in cbks.first .. cbks.last loop
    select loancode into avail from copy_books where num = cbks(i).cb_num;
    select count(date_L) into L_Date from lending where sb_num = cbks(i).sb_num and date_L = cbks(i).date_L;
      if (L_Date = 0) then
        insert into Lending values (cbks(i).cb_num, cbks(i).sb_num, cbks(i).date_L);
        update copy_books set loancode = 'Not' where num = cbks(i).cb_num;
--        cbks(i).date_L := cbks(i).date_L;
    else
      dbms_output.put_line('You can only make ONE LOAN in a day! You have already loaned a book on ' || L_Date);
      cbks.delete;
    end if;
  end loop;
  end after statement;
end chk_DateL;
/
show errors

1 个答案:

答案 0 :(得分:2)

你的循环

FORALL i IN cbks.first .. cbks.last
    insert into lending values cbks(i);

插入到借出表中,这会导致触发器再次执行。因此触发器会自动堆叠直到达到50级,然后oracle通过抛出错误来阻止它。