SQL 기초 실무/SQL 알고리즘 문제

23.09.29. SQL Developer 알고리즘 문제 ⑤

잇꼬 2023. 10. 4. 10:56
728x90
반응형
SMALL

5. 마름모 출력하기

-- 예제115. 마름모를 SQL로 출력하세요
select lpad( ' ', 5-level, ' ' ) || rpad( '★', level, '★' ) as star 
    from dual 
    connect by level < 6 ;

select lpad( ' ', level, ' ' ) || rpad( '★', 5-level, '★') as star
    from dual 
    connect by level < 6 ;
    
select lpad( ' ', 5-level, ' ' ) || rpad( '★', level, '★' ) as star 
    from dual 
    connect by level < 6 -- 삼각형
union all
select lpad( ' ', level, ' ' ) || rpad( '★', 5-level, '★') as star
    from dual 
    connect by level < 6 ; --역삼각형

undefine p_num -- undefine 변수 : 변수의 값을 지움
accept p_num prompt '숫자입력 : '  -- accept : 받아들이다. / prompt : 야기시키다. 
 
 select lpad( ' ', &p_num-level, ' ' ) || rpad( '★', level, '★' ) as star 
    from dual 
    connect by level < &p_num+1 
union all
select lpad( ' ', level, ' ' ) || rpad( '★', (&p_num)-level, '★') as star
    from dual 
    connect by level < &p_num ;    
    
-- 문제1. 다음과 같이 모래시계 모양을 출력하세요.
select lpad( ' ', level, ' ' ) || rpad( '★', (&p_num)-level, '★') as star
    from dual 
    connect by level < &p_num
union all
select lpad( ' ', &p_num-level, ' ' ) || rpad( '★', level, '★' ) as star 
    from dual 
    connect by level < &p_num+1 ;
728x90
반응형
LIST