--------------------------------------------------------
--  DDL for Function PARAM_VALIDATOR
--------------------------------------------------------

  CREATE OR REPLACE EDITIONABLE FUNCTION "ENVX_OPER"."PARAM_VALIDATOR" (pi_value IN CLOB, pi_type IN NUMBER)
   RETURN BOOLEAN
IS
   v_num    NUMBER;
   v_date   DATE;
   v_json   json_object_t;
   v_format VARCHAR2(100);
BEGIN

   SELECT parameter_type_format
     INTO v_format
     FROM system_parameter_type spt
    WHERE id_parameter_type = pi_type;

   -- Intenta convertir el valor a un número
   CASE pi_type
      WHEN 1 THEN 
         --- NUMERO ---
         BEGIN
            v_num := TO_NUMBER(pi_value);
            RETURN true;
         EXCEPTION
            WHEN OTHERS THEN
               RETURN false;
         END;
      WHEN 2 THEN 
         --- FECHA Y HORA ---
         BEGIN
            v_date := TO_DATE(pi_value, 'YYYY-MM-DD');
            RETURN true;
         EXCEPTION
            WHEN OTHERS THEN
               RETURN false;
         END;
      WHEN 3 THEN 
         --- JSON ---
         BEGIN
            v_json := json_object_t.parse(pi_value);
            RETURN true;
         EXCEPTION
            WHEN OTHERS THEN
               RETURN false;
         END;
      WHEN 4 THEN 
         --- LISTA DE VALORES ---
         IF regexp_like(pi_value, '^''[[:alnum:]]+''(,''[[:alnum:]]+'')*$') THEN
            RETURN true;
         ELSE
            RETURN false;
         END IF;

      WHEN 0 THEN 
         --- TEXTO SIN FORMATO ---
         RETURN true;
   END CASE;
   
EXCEPTION
   WHEN OTHERS THEN
      RETURN false;
END;

/
