代码:-------------------------------------------------------------------------------- 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> /