모양 관계상.. 1~9까지..ㅎㅎ
SELECT XMLAGG(XMLELEMENT(NUM,RPAD(TO_CHAR(NUM,’00’),4,’ ’))
ORDER BY LINE_Y ASC).EXTRACT(’//text()’).GetStringVal() RESULT
FROM (
SELECT NUM,
DECODE(RID_GRP,1,RID_LO+1,
2,RID_LO+RID_RNK+1,
3,N-RID_LO,
4,N-(RID_LO+RID_RNK)
) LINE_X,
DECODE(RID_GRP,1,RID_RNK+RID_LO,
2,N-RID_LO,
3,N-RID_RNK-RID_LO,
4,RID_LO+1
) LINE_Y
FROM (
SELECT /*+ORDERED USE_NL(A,B)*/
N,
RID,
DECODE(RID_GRP,0,4,RID_GRP) RID_GRP,
TRUNC((RID-1)/4) RID_LO,
ROW_NUMBER() OVER(PARTITION BY RID ORDER BY RID) RID_RNK,
ROWNUM NUM
FROM (
SELECT N,
NO RID,
MOD(NO,4) RID_GRP,
ROW_NUMBER() OVER(PARTITION BY MOD(NO,2) ORDER BY NO DESC) NUM_CNT
FROM (
SELECT 9 N -- 자연수 넣으세요
FROM DUAL
) D, COPY_T
WHERE NO <= (N*2)-1
ORDER BY RID
) A, COPY_T B
WHERE A.NUM_CNT >= B.NO
)
)
GROUP BY LINE_X;