15 27 35 25 11 16 28 36 40 34 24 10 1 17 29 37 41 39 33 23 9 2 18 30 38 32 22 8 3 19 31 21 7 4 20 6 5
已选择9行。
SQL> exec :n := 8
PL/SQL 过程已成功完成。
SQL> /
STR ---------------------------------------------------------------------------------------------------------------------- 5 4 6 18 17 3 7 19 27 26 16 2 8 20 28 32 31 25 15 1 9 21 29 30 24 14 10 22 23 13 11 12
对于比较大的N值, 需对"顺时针螺旋特征码"的组成进行适当修改:
代码:-------------------------------------------------------------------------------- 1 select replace(max(sys_connect_by_path(rank, '''','''')), '''','''') str 2 from (select i, j, 3 case when rank() over(order by tag) - floor(:n * :n / 2) <= 0 then '''' '''' 4 else to_char(rank() over(order by tag) - floor(:n * :n / 2), ''''9999'''') end as rank, 5 min(j) over(partition by i) minj 6 from (select i, 7 j, 8 -- 逆时针螺旋特征码 counter-clockwise 9 case greatest(i - j, i + j - :n - 1, j - i, :n - i - j + 1) 10 when i - j then 11 chr(:n - (i - j)) || ''''1'''' || chr(i) 12 when i + j - :n - 1 then 13 chr(:n - (i + j - :n - 1)) || ''''2'''' || chr(j) 14 when j - i then 15 chr(:n - (j - i)) || ''''3'''' || chr((:n - i)) 16 when :n - i - j + 1 then 17 chr(:n - (:n - i - j + 1)) || ''''4'''' || chr(i) 18 end as tag 19 from (select level as i from dual connect by level <= :n) a, 20 (select level as j from dual connect by level <= :n) b 21 -- where abs(i - j) < floor(:n / 2 + .6) 22 -- and i + j between floor(:n / 2 + .6) + 1 and floor(:n / 2 + .6) + :n 23 ) 24 ) 25 start with j = minj 26 connect by j - 1 = prior j and i = prior i 27 group by i 28* order by i SQL> /
STR ------------------------------------------------------------------------------------------------------------------- 19 20 40 18 21 41 57 39 17 &nbs 上一页 [1] [2] [3] [4] [5] [6] 下一页 |