Bom dia Colegas!
Ao tentar criar uma Function/Trigger dá o erro:
ERRO: erro de sintaxe em ou próximo a "else"
LINE 18: else
e não consigo entender qual o motivo, abaixo a function.
create or replace function apagar_aiu() returns trigger
as $$
declare
vlr_total numeric(12,2);
hist varchar(50);
begin
if (TG = 'INSERT') then
begin
if (new.data_pagamento is not null) then
begin
if (new.data_pagamento <= new.data_vencimento) then
begin
if (new.data_pagamento <= new.validade_desconto) then
vlr_total = new.valor - new.desconto;
else
vlr_total = new.valor;
end if;
end <<< --- Linha 18 :-@
else
vlr_total = new.valor + new.acrescimo;
end if;
hist = 'Vlr. ref. pagto. do título '||new.numero_titulo;
insert into movimento_caixa (data, descricao, valor, d_c, documento)
values (new.data_pagamento, :hist, :vlr_total, 'D',
new.numero_titulo);
end if;
end
else
begin
if (TG = 'UPDATE') then
begin
if (new.data_pagamento <> old.data_pagamento) then
begin
vlr_total = new.valor + new.acrescimo - new.desconto;
update movimento_caixa mc
set mc.data = new.data_pagamento, mc.valor = :vlr_total
where mc.data = old.data_pagamento
and mc.documento = new.numero_titulo
and mc.d_c = 'D';
end if;
if (new.valor <> old.valor) then
begin
vlr_total = new.valor + new.acrescimo - new.desconto;
update movimento_caixa mc
set mc.valor = :vlr_total
where mc.data = old.data_pagamento
and mc.documento = old.numero_titulo
and mc.d_c = 'D';
end if;
if (new.numero_titulo <> old.numero_titulo) then
begin
update movimento_caixa mc
set mc.documento = new.numero_titulo
where mc.data = old.data_pagamento
and mc.documento = old.numero_titulo
and mc.d_c = 'D';
end if;
end if;
end
end;
$$ LANGUAGE plpgsql;
--
[]'s,
Hélio Oliveira
Bel. Ciência da Computação
Técnico em Contabilidade
e-mail : [email protected]
Skype : hpensador
http://hpensador.blogspot.com/
www.hpensador.net
(71) 9975-9176
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral