CREATE OR REPLACE FUNCTION fn_fco_ult_dia_mes
(psi_anio number, pti_mes number)
RETURN number
AS
  vti_dias number(2);
  vdt_fecha date;
  vbl_ok boolean;
BEGIN

    vti_dias := 1;
    BEGIN
      SELECT DECODE(pti_mes, 1, 31, 2, 28, 3, 31, 4, 30, 5, 31, 6, 30, 7, 31, 8, 31, 9, 30, 10, 31, 11, 30, 12, 31)
/*
            CASE pti_mes
            WHEN  1 THEN 31 WHEN  2 THEN 28 WHEN  3 THEN 31
            WHEN  4 THEN 30 WHEN  5 THEN 31 WHEN  6 THEN 30
            WHEN  7 THEN 31 WHEN  8 THEN 31 WHEN  9 THEN 30
            WHEN 10 THEN 31 WHEN 11 THEN 30 WHEN 12 THEN 31
          END
 */
      INTO vti_dias
      FROM dual;
    EXCEPTION
        WHEN OTHERS THEN vti_dias := 1;
    END;

    IF pti_mes = 2 THEN
       vbl_ok := true;
       BEGIN
            vdt_fecha := TO_DATE((RTRIM(psi_anio) || '0229'),'YYYYMMDD');
       EXCEPTION
          WHEN OTHERS THEN vbl_ok := false;
       END;

        IF vbl_ok THEN
            vti_dias := 29;
        END IF;
    END IF;

    RETURN vti_dias;
END;
/
CREATE PUBLIC SYNONYM fn_fco_ult_dia_mes FOR ADAM.fn_fco_ult_dia_mes;
GRANT ALL ON fn_fco_ult_dia_mes TO ADAMA;
