x
1
declare
2
internalid integer;
3
begin
4
--DESCRICAO NULA
5
if descricao is null then
6
RAISE EXCEPTION 'descricao = %', descricao
7
USING HINT = 'Field descricao must be not null';
8
end if;
9
10
--IDNATIVO NULO OU FORA DO PADRAO
11
if idnativo is null or idnativo not in (0,1,-99999) then
12
RAISE EXCEPTION 'idnativo = %', idnativo
13
USING HINT = 'Field must not be null or different from 1 or 0.';
14
end if;
15
16
--IDNPADRAO NULO OU FORA DO PADRAO
17
if idnpadrao is null or idnpadrao not in (0,1) then
18
RAISE EXCEPTION 'idnpadrao = %', idnpadrao
19
USING HINT = 'Field must not be null or different from 1 or 0.';
20
end if;
21
22
--CODIGOERP NULO
23
if externalid is null or externalid = '' then
24
RAISE EXCEPTION 'externalid = %', externalid
25
USING HINT = 'Field externalid must be not null';
26
end if;
27
28
--VALIDAÇÃO DE CODIGOERP JÁ EXISTENTE
29
IF (select distinct 1 FROM TIPOLIMITECREDITO WHERE CODIGOERP = PostTipoLimiteCredito.externalid) = 1
30
THEN RAISE EXCEPTION 'externalid = %', PostTipoLimiteCredito.externalid
31
USING HINT = 'The record (externalid = '|| PostTipoLimiteCredito.externalid ||') already exists, it was not possible to insert it.';
32
ELSE insert into tipolimitecredito (idtipolimitecredito,descricao, idnativo, idnpadrao, sgltipolimitecredito, codigo, codigoerp) values (nextval('seqpktipolimitecredito'), descricao, idnativo, idnpadrao, externalid, externalid, externalid) returning idtipolimitecredito into internalid;
33
end if;
34
35
return query select internalid;
36
END;