连续插入相同的新记录时,触发器为何不发生作用?
create or replace trigger tri_voucher_唯一性
before insert on voucher
for each row
declare
i int := 0;
begin
/*select * from (select * from voucher where occured_date <= SYSDATE AND occured_date > to_date(EXTRACT(year from sysdate)-1||'/12'||'/31','YYYY/MM/DD')) A
WHERE A.GENERAL_WORD like '06付%';*/
--取当年度所有相同总字第几字的值之和;
select count(*)
into i
from (select *
from voucher
where occured_date <= SYSDATE
AND occured_date >
to_date(EXTRACT(year from sysdate) - 1 || '/12' || '/31',
'YYYY/MM/DD')) A
Where general_word = :new.general_word
and sequence_nbr = :new.sequence_nbr;
if (i > 0) then
raise_application_error(-20001,
'在本会计年度,已存在相同的序列号和总字号');
end if;
end tri_voucher_唯一性;