|
|
SQL> with t(c) as (select level-1 from dual connect by level <= 2+1),
2 s(n,v) as (select 1,cast(c as varchar2(10)) from t
3 union all
4 select n+1,
5 s.v||t.c
6 from s,t
7 where n < 4
8 and case when t.c > 0 then
9 case when mod(n+1,2)=1 then
10 case when ceil((n+1)/2) = 1 then 1
11 when ceil((n+1)/2) > 1 and t.c <> substr(s.v,-2,1) then 1
12 else 0
13 end
14 else
15 case when ceil((n+1)/2) = 1 and t.c <> substr(s.v,-1,1) then 1
16 when ceil((n+1)/2) > 1 and t.c <> substr(s.v,-2,1) and t.c <> substr(s.v,-1,1) then 1
17 else 0
18 end
19 end
20 else 1
21 end = 1
22 )
23 select * from s where regexp_count(v,0)=1 and n=4
24 /
N V
---------- --------------------------------------------------------------------------------
4 1220
4 1201
4 1021
4 2110
4 2102
4 2012
4 0112
4 0221
8 rows selected |
|