|
|
SQL> with t(c) as (select level-1 from dual connect by level <= 3+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 < 3*3
8 and case when t.c > 0 then
9 case when mod(n+1,3)=1 then
10 case when ceil((n+1)/3) = 1 then 1
11 when ceil((n+1)/3) > 1 and t.c <> substr(s.v,-3,1) then 1
12 else 0
13 end
14 else
15 case when ceil((n+1)/3) = 1 and t.c <> substr(s.v,-1,1) then 1
16 when ceil((n+1)/3) > 1 and t.c <> substr(s.v,-3,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 count(*)
24 from s
25 where regexp_count(v,0)=(3*3-(2*3-1))
26 and n=3*3
27 and instr(v,'1')>0
28 and instr(v,'2')>0
29 and instr(v,'3')>0
30 /
COUNT(*)
----------
7080 |
|