Code Listing 3: Workaround function for optimal_plan

CREATE OR REPLACE PACKAGE analyze_rates_wa
IS
   FUNCTION optimal_plan (id_in IN company.ID%TYPE)
      RETURN analyze_rates.optimal_info_rt;
END analyze_rates_wa; 
/

CREATE OR REPLACE PACKAGE BODY analyze_rates_wa
IS
   FUNCTION optimal_plan (id_in IN company.ID%TYPE)
      RETURN analyze_rates.optimal_info_rt
   IS
      retval analyze_rates.optimal_info_rt;
   BEGIN
      retval := analyze_rates.optimal_plan (id_in);
          
     -- Workaround for bug #2056689: is_optimal always returns TRUE; a plan is not
     -- optimal if level and rate are both null. When bug is fixed, remove the following
     -- line and then we will be using the new functionality!
          
      retval.is_optimal :=
           NOT (retval.rate_level IS NULL AND retval.rate_type IS NULL
               );
                           
      RETURN retval;
   END optimal_plan;
END analyze_rates_wa;
/