#Oracle SQL, 177 bytes
Oracle SQL, 177 bytes
Create a collection type (31 bytes):
CREATE TYPE t IS TABLE OF INT; Then use the query (146 bytes):
WITH n(a,b,c)AS(SELECT a,b,t()FROM i UNION ALL SELECT a,b-1,c MULTISET UNION t(COLUMN_VALUE)FROM n,TABLE(n.a)WHERE b>=0)SELECT c FROM n WHERE b=0 Assuming that the input parameters are in the table i with columns a and b:
CREATE TABLE i (a t,b INT) NESTED TABLE a STORE AS t_a; INSERT INTO i VALUES ( t(1,2,3), 3 ); | C | |-------| | 1,1,1 | | 1,1,2 | | 1,1,3 | | 1,2,1 | | 1,2,2 | | 1,2,3 | | 1,3,1 | | 1,3,2 | | 1,3,3 | | 2,1,1 | | 2,1,2 | | 2,1,3 | | 2,2,1 | | 2,2,2 | | 2,2,3 | | 2,3,1 | | 2,3,2 | | 2,3,3 | | 3,1,1 | | 3,1,2 | | 3,1,3 | | 3,2,1 | | 3,2,2 | | 3,2,3 | | 3,3,1 | | 3,3,2 | | 3,3,3 |