SET TERM ^ ;

CREATE OR ALTER function FN_CALC_VALOR_COTA (
    CENTRO_NEGOCIO_ID integer,
    VALOR numeric(15,4),
    PERCENTUAL numeric(15,1))
returns numeric(15,4)
AS
declare variable VALOR_RET numeric(15,4);
begin
  :VALOR_RET = :VALOR;

  IF(:PERCENTUAL > 0) THEN
  BEGIN
    :VALOR_RET = CAST(CAST(:VALOR AS DOUBLE PRECISION) * CAST((CAST(:PERCENTUAL AS DOUBLE PRECISION) / 100.00) AS DOUBLE PRECISION) AS DOUBLE PRECISION);
  END

  return :VALOR_RET;
end
^

SET TERM ; ^

