여백 만들기

2014.11.26 19:30 from database/oracle
/* Formatted on 2014/11/26 오후 7:31:59 (QP5 v5.256.13226.35510) */
WITH M
     AS (SELECT 1 AS seq, 'A' AS val FROM DUAL
         UNION ALL
         SELECT 2 AS seq, 'B' AS val FROM DUAL
         UNION ALL
         SELECT 3 AS seq, 'C' AS val FROM DUAL
         UNION ALL
         SELECT 4 AS seq, 'E' AS val FROM DUAL
         UNION ALL
         SELECT 5 AS seq, 'E' AS val FROM DUAL)
SELECT seq, val FROM M
UNION ALL
    SELECT ROWNUM + (SELECT COUNT (*) FROM M) AS seq,
           DECODE (ROWNUM, 1, '-이하여백-', NULL)
      FROM (SELECT '' val
              FROM DUAL
             WHERE 0 <
                      MOD (
                         (CASE
                             WHEN (SELECT COUNT (*) FROM M) = 0 THEN 29
                             ELSE (SELECT COUNT (*) FROM M)
                          END),
                         30)                           -- 30으로 딱 떨어질때를 위한 제동장치
                            ) S
CONNECT BY LEVEL <=
                30
              - MOD (
                   (CASE
                       WHEN (SELECT COUNT (*) FROM M) = 0 THEN 29
                       ELSE (SELECT COUNT (*) FROM M)
                    END),
                   30)
Posted by 두억시니 트랙백 0 : 댓글 0