Skip to content
Advertisement

all combination of two symbol with nth length

I need a solution using only oracle sql query

Input two static symbol ‘A’ and ‘B’ n – number

Output if N=3 must give all combination using this symbols

AAA AAB ABA BAA …

Output if N=4 must give all combination using this symbols

AAAA AAAB AABA ABAA …

Advertisement

Answer

Old style connect by hierarchical query

with i(s) as
( 
SELECT 'A' FROM DUAL UNION ALL
SELECT 'B' FROM DUAL 
)
select replace(s, ' ', '') s
from (
  select SYS_CONNECT_BY_PATH(s,' ') s, level l
  from i
  connect by level <= 4
) t
where l = 4
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement