Oracle - Issues with to_date

159 views Asked by At

I'm trying to insert values on a table like this:

insert into Semana (edicao,planeamentosemanal,diaInicio,diaFim)
values (1,'Introducao a cadeira', to_date('2011/12/12','yyyy/mm/dd'),to_date('2012/07/11','yyyy/mm/dd'));

But for some reason I'm unaware of the last 2 values are passed as null so my trigger won't work as it's supposed to. I tried to print the values of :new.diaInicio and :new.diaFim and they are null.

The trigger is:

create or replace TRIGGER "T_SEMANA" before insert on semana
for each row
declare

codigoSemana number;
diaInicio date;
diaFim date;

begin
--Verificar se existem semanas repetidas
  begin

    select s.codigo into codigoSemana from Edicao e
    join Semana s on e.codigo = s.edicao
    where e.codigo = :new.edicao and (s.diaInicio = :new.diaInicio or (:new.diaInicio > s.diaInicio and :new.diaInicio < s.diaFim));

    exception
      when no_data_found then
        null;

  end;

--Verificar se a variavel é nula ou nao. Caso nao o seja, nao pode ser inserida
  if codigoSemana is not null then
    raise_application_error(-20001,'Erro ao inserir o registo na base de dados.');
  end if;

--Verificar se a semana comeca e acaba dentro do ano lectivo
  begin

    select a.diaInicio into diaInicio from Semana s
    join Edicao e on e.codigo = s.edicao
    join AnoLectivo a on a.codigo = e.anoLectivo;

    select a.diaFim into diaFim from Semana s
    join Edicao e on e.codigo = s.edicao
    join AnoLectivo a on a.codigo = e.anoLectivo;

    exception
      when no_data_found then
        null;

  end;

  if (:new.diaInicio > diaInicio or :new.diaFim < diaFim) then
    null;
  else
    raise_application_error(-20001,'Os dias da semana devem de coincidir com os do ano lectivo.');
  end if;

--Incrementar o código
  :new.codigo := codsemana.nextval;

end;

What seems to be the problem?

1

There are 1 answers

0
Bowdzone On

Copied from question:

The problem was that I was trying to access the table which fired the trigger. All I had to do is change the query.