|
|
#5
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 mod(n+1,3)=1 then
9 case when ceil((n+1)/3) = 1 then 1
10 when ceil((n+1)/3) > 1 and t.c <> substr(s.v,-3,1) then 1
11 else 0
12 end
13 else
14 case when ceil((n+1)/3) = 1 and t.c <> substr(s.v,-1,1) then 1
15 when ceil((n+1)/3) > 1 and t.c <> substr(s.v,-3,1) and t.c <> substr(s.v,-1,1) then 1
16 else 0
17 end
18 end = 1
19 )
20 select count(v) from s where regexp_count(v,0)=(3*3-(2*3-1)) and n=3*3
21 /
COUNT(V)
----------
723
|
|