
stevewaltz |
I believe you are trying to choose all the distinct ways n numbers can be chosen from the first k positive integers without regard to order. By “without regard to order” I mean, for instance, that (1,2,3); (1,3,2); (2,1,3); (2,3,1); (3,1,2); and (3,2,1) are considered the same set of the 3 digits 1, 2 and 3. One way to do it is to create a single column table of integers (Oracle has had a way to do this without actually creating a table for a while now). The SQL below will work for the specific example. With this technique, k can be varied easily or provided as a variable, but the SQL has to be modified to deal with different values of n. (Just curious; why is the subject “Generating Random numbers in SQL”?)
select a.integer_value b1,
b.integer_value b2,
c.integer_value b3
from integer_table a,
integer_table b,
integer_table c
where a.integer_value <b>