17 Nisan 2014 Perşembe

[ORACLE SQL] Combination Calculation

You replace the string 'ALI' with any type you prefer and use to calculate combination of strings by letters.


WITH got_a_char AS
(SELECT 'ALI' AS txt, substr('ALI', LEVEL, 1) AS a_char, LEVEL AS n
    FROM dual
  CONNECT BY LEVEL <= length('ALI'))
SELECT DISTINCT REPLACE(sys_connect_by_path(a_char, '~~'), '~~') AS perm
  FROM got_a_char
WHERE LEVEL = length(txt)
CONNECT BY nocycle txt = PRIOR txt

       AND n != PRIOR n;

Result:

LIA
ILA
ALI
IAL
LAI
AIL

Hiç yorum yok:

Yorum Gönder