퀴즈요~^^* 0 1 3,852

by 박종정 [2008.09.03 15:03:32]


01.JPG (21,051Bytes)
02.JPG (17,372Bytes)
03.JPG (13,958Bytes)
04.JPG (28,383Bytes)
05.JPG (10,998Bytes)

변수 n, m을 가지고 아래 그림과 같이 표현하는 쿼리구요~

삼각형과 역삼각형을 이용한 모양 만들기 입니다~^^

 

Copy테이블 혹은 Connect By 절은 한번만 쓰도록 하세요~^^*

 

감사합니다~

 

 

by 맹 [2008.11.14 14:55:59]
오라클 버전때문인지 connect by 절을 쓰면 최대 100로우만 생기네요
그래서 copy_t 테이블을 엮어서..

-- 1, 2, 3 and etc

select q
,rn
,lpad(' ', ((n * 2 - 1) - lengthb(str)) / 2, ' ') || str ||
lpad(' ', ((n * 2 - 1) - lengthb(str)) / 2, ' ')
from (select q
,n
,rn rn
,greatest(case
when rn <= n then
rpad('*', (rn * 2) - 1, '*')
else
' '
end, case
when rn - trunc(n / 3) > 0 then
rpad('*', (n - (rn - trunc(n / 3) - 1)) * 2 - 1, '*')
else
' '
end) str
from (select 'No.1' q
,8 n
from dual
union all
select 'No.2'
,7 n
from dual
union all
select 'No.3'
,6 n
from dual
union all
select 'No.etc'
,50 n
from dual)
,copy_t t
where t.rn <= n + trunc(n / 3));


-- 4, 5

select q, lpad(' ', (rowcnt - lengthb(str)) / 2, ' ') || str ||
lpad(' ', (rowcnt - lengthb(str)) / 2, ' ')
from (select q, rowcnt
,rpad('*', (rowcnt) - abs(rn - n) * 2, '*') str
from (select 'No.4' q, 8 n
,8 * 2 - 1 rowcnt
from dual
union all
select 'No.5' q, 4 n
,4 * 2 - 1 rowcnt
from dual)
,copy_t
where rn <= rowcnt);
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입