Re: is there better way than the call a function twice.

  • From: Stephane Faroult <sfaroult@xxxxxxxxxxxx>
  • To: "'Oracle L (E-mail)'" <oracle-l@xxxxxxxxxxxxx>, "Kathy'" <kduret@xxxxxxxxxxxxxxxxxxxx>
  • Date: Wed, 3 Nov 2004 10:47:39 +0100

 
I usually try to get rid of function calls, especially costly ones, in SQL
statements but when everything fails I try to use packaged variables, eg 

create package wrapper 

as 

    function ugly_func(param in some_type) 

    return whatever; 

end; 

create package body wrapper 

as 

   hidden_var                    whatever; 

   previous_parameter      some_type := NULL; 

   function ugly_func(param in some_type)
   return whatever
   is
   begin
     if (param = previous_parameter)
     then
        --  Unless the function calls a random function ...
        return hidden_var;
    end if;
    hidden_var := ugly_function(param);
    previous_parameter := param;
    return hidden_var;
  end;
end;

and replace calls to ugly_function with calls to wrapper.ugly_func.

Regards, 

Stephane Faroult 

RoughSea Ltd 
http://www.roughsea.com 


On Tue, 2 Nov 2004 16:49 , 'Duret, Kathy' <kduret@xxxxxxxxxxxxxxxxxxxx>
sent:

oh magic eight ball is there a better way than calling a ugly function twice
when I need two columns returned with the same value.

I hate the call the function twice because it is very costly.

what I need to do is: 
select x,y,z, ugly_function as ugly1, ugly_function ugly2 from a

when I do.... it actually gives me worse results ie. more physical reads....

select x,y,z , ugly1, ugly1 as ugly2 from (
select x,y,z, ugly_function ugly1 from a) 

Is there anyway around this?


Kathy.








This transmission contains information solely for intended recipient and may
be privileged, confidential and/or otherwise protect from disclosure. If
you are not the intended recipient, please contact the sender and delete all
copies of this transmission. This message and/or the materials contained
herein are not an offer to sell, or a solicitation of an offer to buy, any
securities or other instruments. The information has been obtained or
derived from sources believed by us to be reliable, but we do not represent
that it is accurate or complete. Any opinions or estimates contained in
this information constitute our judgment as of this date and are subject to
change without notice. Any information you share with us will be used in
the operation of our business, and we do not request and do not want any
material, nonpublic information. Absent an express prior written agreement,
we are not agreeing to treat any information confidentially and will use any
and all information and reserve the right to publish or disclose any
information you share with us.
--
//www.freelists.org/webpage/oracle-l[1]



--- Links ---
   1 
modules/refer.pl?redirect=http%3A%2F%2Fwww.freelists.org%2Fwebpage%2Foracle-l
--
//www.freelists.org/webpage/oracle-l

Other related posts: