TOTVS CRM | SFA - 12.1.2501
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
postsegmento(character varying, integer, character varying)
Parameters
Name
Type
Mode
descricao
character varying
IN
idnativo
integer
IN
externalid
character varying
IN
Definition
declare internalid integer; begin --DESCRICAO NULA if descricao is null then RAISE EXCEPTION 'descricao = %', descricao USING HINT = 'Field descricao must be not null'; end if; --IDNATIVO NULO OU FORA DO PADRAO if idnativo is null or idnativo not in (0,1,-99999) then RAISE EXCEPTION 'idnativo = %', idnativo USING HINT = 'Field must not be null or different from 1 or 0.'; end if; --CODIGOERP NULO if externalid is null or externalid = '' then RAISE EXCEPTION 'externalid = %', externalid USING HINT = 'Field externalid must be not null'; end if; --VALIDAÇÃO DE CODIGOERP JÁ EXISTENTE IF (select distinct 1 FROM SEGMENTO WHERE CODIGOERP = PostSegmento.externalid) = 1 THEN RAISE EXCEPTION 'externalid = %', PostSegmento.externalid USING HINT = 'The record (externalid = '|| PostSegmento.externalid ||') already exists, it was not possible to insert it.'; ELSE insert into segmento (idsegmento,descricao, idnativo, idnconsomecotasupervisor, codigo, codigoerp) values (nextval('seqpksegmento'),descricao, idnativo, 0, externalid, externalid) returning idsegmento into internalid; end if; return query select internalid; END;