create or replace trigger insBef_requisicao
before insert on requisicao
for each row
declare
i_estado_req exemplares.estado_req%type;
i_num_max_req tipo_utente.num_max_req%type;
total_req number(10);
total_req_atraso number(10);
begin
if:new.data_prev_ent < data_requisicao
raise_application_error(-20100,'Data prevista de entrega não pode ser anterior a data de requisicao');
end if;
if:new.devolucao='S'
raise_application_error(-20100,'quando insere requisicao o estado da requisicao tem de ser N');
end if;
select estado_req into i_estado_req from exemplares where id_exemplar= :new.id_exemplar;
if i_estado_req='S'
raise_application_error(-20100,'Este Livro já esta requisitado');
end if;
select a.cod_utente,b.cod_utente, b.tipo_utente, c.utente, c.num_max_req into i_num_max_req from requisicao a, utentes b, tipo_utente c
where a.code_utente=b.utente and b.tipo_utente=c.tipo_utente;
select count(*) into total_req from requisicao where cod_utente=:new.cod_utente;
if i_num_max_req < total_req
raise_application_error(-20100,'ultrapassou o total de requisicoes');
end if;
select count(*) into total_req_atraso from requisicao where cod_utente=:new.cod_utente and devolucao='N' and
data_prev_ent > sysdate;
if total_req_atraso > 0
raise_application_error(-20100,'tem livros em atraso');
end if;
end;
/
Olhando assim por cima eu acho que o erro esta no IF
o correto e:
if:new.data_prev_ent < data_requisicao THEN
raise_application_error(-20100,'Data prevista de entrega não pode ser anterior a data de requisicao');
end if;
select c.num_max_req
into i_num_max_req
from requisicao a,utentes b, tipo_utente c
where a.cod_utente=b.cod_utente
and b.tipo_utente=c.tipo_utente
and a.cod_utente=:new.cod_utente;