public static Object nvl(CompiledValue arg1, CompiledValue arg2, ExecutionContext context)
     throws FunctionDomainException, TypeMismatchException, NameResolutionException,
         QueryInvocationTargetException {
   Object value = arg1.evaluate(context);
   if (value == null) {
     return arg2.evaluate(context);
   }
   return value;
 }
  public static Date to_date(CompiledValue cv1, CompiledValue cv2, ExecutionContext context)
      throws FunctionDomainException, TypeMismatchException, NameResolutionException,
          QueryInvocationTargetException {
    Object value1 = cv1.evaluate(context);
    Object value2 = cv2.evaluate(context);
    if (!(value1 instanceof String) || !(value2 instanceof String)) {
      throw new QueryInvalidException(
          LocalizedStrings
              .Functions_PARAMETERS_TO_THE_TO_DATE_FUNCTION_SHOULD_BE_STRICTLY_SIMPLE_STRINGS
              .toLocalizedString());
    }
    String dateStr = (String) value1;
    String format = (String) value2;
    Date dt = null;
    try {
      // Removed the following line so that to data format conforms to
      // SimpleDateFormat exactly (bug 39144)
      // format = ((format.replaceAll("Y", "y")).replaceAll("m", "M")).replaceAll("D", "d");

      /*if((format.indexOf("MM") == -1 && format.indexOf("M") == -1) || (format.
      indexOf("dd") == -1 && format.indexOf("d") == -1) || (format.indexOf("yyyy") ==
      -1 && format.indexOf("yy") == -1))
            {
              throw new QueryInvalidException("Malformed date format string");
            }
            if(format.indexOf("MMM") != -1 || format.indexOf("ddd") != -1 || format.in
      dexOf("yyyyy") != -1)
            {
              throw new QueryInvalidException("Malformed date format string");
            } */

      SimpleDateFormat sdf1 = new SimpleDateFormat(format);
      dt = sdf1.parse(dateStr);

    } catch (Exception ex) {
      throw new QueryInvalidException(
          LocalizedStrings.Functions_MALFORMED_DATE_FORMAT_STRING_AS_THE_FORMAT_IS_0
              .toLocalizedString(format),
          ex);
    }
    return dt;
  }