Re: Seeking recursive solution to replace nested for-loops
Date: Fri, 20 Feb 2004 12:14:11 -0500
Message-ID: <kKmdnaGUZ6o_3avdRVn-hQ_at_comcast.com>
"Michelle Romano" <mromano_at_sensis.com> wrote in message
news:aaba7f35.0402190919.31edd67f_at_posting.google.com...
| Working with PL/SQL and Oracle9i, I am looking for a better way to
| generate combinations of n objects taken k at a time:
| n!/k!(n-k)!
| I am currently using the nested for-loop concept, but it is very
| inefficient since the value of k can vary.
|
| Does anyone know of a recursive solution or a better iterative
| solution using PL/SQL? Even a code sample which demonstrates
| recursion would give me a good place to start.
|
| Thanks in advance for your help.
|
| Michelle
real simple recursion example:
create or replace procedure recurse ( ip_levels in number )
is
begin
dbms_output.put_line( ip_levels );
if ip_levels > 0
then
recurse(ip_levels-1);
end if;
dbms_output.put_line( 'exiting ' || ip_levels );
end recurse;
/
set serveroutput on
exec recurse(10)
10
9
8
7
6
5
4
3
2
1
0
exiting 0
exiting 1
exiting 2
exiting 3
exiting 4
exiting 5
exiting 6
exiting 7
exiting 8
exiting 9
exiting 10
;-{ mcs Received on Fri Feb 20 2004 - 18:14:11 CET