Re: Seeking recursive solution to replace nested for-loops

From: Dave <davidr21_at_hotmail.com>
Date: 2 Mar 2004 21:31:04 -0800
Message-ID: <8244b794.0403022131.54687aa8_at_posting.google.com>


mromano_at_sensis.com (Michelle Romano) wrote in message news:<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

[Quoted] Ah...I see. Would you mind posting your current nested-loop solution as a starting point?

Thanks,
Dave Received on Wed Mar 03 2004 - 06:31:04 CET

Original text of this message