Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Declaring a function ...

Re: Declaring a function ...

From: Christopher Beck <clbeck_at_us.oracle.com>
Date: Thu, 29 Jul 1999 17:18:19 GMT
Message-ID: <37a58ad6.102706564@inet16.us.oracle.com>


On Thu, 29 Jul 1999 18:52:13 +0200, Anonymous <nobody_at_newsfeeds.com> wrote:

>
>I would like to create a function without knowing the number of arguments
>like GREATEST(a1, a2, ...).
>
>Does anyone know the syntax ?
>An example please !!! :-)

You can't do it directly, but you can use a user defined type in Oracle 8 to achieve the same result.

eg.

SQL> create or replace
  2 type argv as
  3 table of number;
  4 /
Type created.

SQL> l
  1 create or replace
  2 function my_greatest( p_list argv ) return number as   3 l_greatest number;
  4 begin
  5 l_greatest := p_list(1);
  6 for i in 2 .. p_list.count loop

  7      if p_list(i) > l_greatest then
  8        l_greatest := p_list(i);
  9      end if;

 10 end loop;
 11 return l_greatest;
 12* end my_greatest;
SQL> /
Function created.

SQL> begin
  2 dbms_output.put_line( my_greatest( argv( 1,2,3,4,5 ) ) );   3 end;
  4 /

5
PL/SQL procedure successfully completed.

SQL> begin
  2 dbms_output.put_line( my_greatest( argv( 1,2,3,4,5,6,7,8,9,10) ) );   3 end;
  4 /

10
PL/SQL procedure successfully completed.

hope this helps.

chris.

>
>Thank !!!
>
>
>San_at_a2c.fr
>
>
>
> --------== Posted Anonymously via Newsfeeds.Com ==-------
> Featuring the worlds only Anonymous Usenet Server
> -----------== http://www.newsfeeds.com ==----------

--
Christopher Beck
Oracle Corporation
clbeck_at_us.oracle.com
Reston, VA.



Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Thu Jul 29 1999 - 12:18:19 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US