Re: Seeking recursive solution to replace nested for-loops

From: Michelle Romano <mromano_at_sensis.com>
Date: 2 Mar 2004 06:07:14 -0800
Message-ID: <aaba7f35.0403020607.1d4ea02e_at_posting.google.com>


> How about this?
>
> create or replace function factorial(p_number in number) return number
> is
> begin
> if p_number = 1
> then
> return 1;
> else
> return factorial(p_number-1) * p_number;
> end if;
> end;
> /
>
> create or replace function bd(p_n in number, p_k in number) return number
> is
> begin
> return factorial(p_n) / ( factorial(p_k) * factorial(p_n-p_k) );
> end;
> /
>
> SQL> select bd(16, 4) from dual;
>
> BD(16,4)
> ----------
> 1820
>
> Dave

Dave,

Your solution is great for obtaining the result of a numerical combination, but unfortunately, it is not exactly what I'm looking for. I apologize for not including more detail in my original message.

I am working with non-numeric parameters and need the function to return each combination. For example, if my parameters are a, b, c, d, e
and I am looking for combinations in threes, the result would be:

a,b,c a,b,d a,b,e a,c,d a,c,e a,d,e b,c,d b,c,e b,d,e c,d,e

Once I obtain this result, I will be running a series of procedures against each combination.

Michelle Received on Tue Mar 02 2004 - 15:07:14 CET

Original text of this message