SQL

날짜, 시각

에어팟맥스 2022. 7. 4. 19:53

날짜 타입은 date 이다.
    date 타입의 기본적인 표현방식은 'RR/MM/DD' 으로 나타내어진다.
    RR 은 년도의 두 자리만 나타내는데 50~99 는 1950~1999 을 말하는 것이다.
    RR 은 년도의 두 자리만 나타내는데 00~49 는 2000~2049 을 말하는 것이다.

 

 

 --- *** 현재 시각을 알려주는 것 *** ---

 select sysdate, current_date, localtimestamp, current_timestamp, systimestamp
    from dual;
    -- 22/06/30	22/06/30	22/06/30 15:28:18.512000000	22/06/30 15:28:18.512000000 ASIA/SEOUL	22/06/30 15:28:18.512000000 +09:00

 

	select sysdate
         , to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss')
    --   , to_char(sysdate, 'yyyy-mm-dd hh:mi:ss')
    --   , to_char(sysdate, 'yyyy-mm-dd am hh:mi:ss')
    --   , to_char(sysdate, 'yyyy-mm-dd pm hh:mi:ss')
    from dual;
 	select employee_id 사원번호
         , first_name || ' ' || last_name 사원명   
         , to_char(hire_date, 'yyyy/mm/dd') 입사일자
    --   , to_char(hire_date, 'yyyy')||'년 '||to_char(hire_date, 'mm')||'월 '||to_char(hire_date, 'dd')||'일' 입사일자
    from employees;
	select hire_date
    from employees
    where employee_id = 154;
    -- 06/12/09
    
    update employees set hire_date = to date('2006-12-31 09:00:00', 'yyyy-mm-dd hh24:mi:ss')
    where employee_id = 154;

 

 

 

-- employees 테이블에서 입사일자가 2005년 1월 1일 부터 2006년 12월 31일 까지 입사한 사원들만
    -- 사원번호, 사원명, 입사일자를 나타내시오

 

    select employee_id 사원번호
         , first_name || ' ' || last_name 사원명
         , hire_date 입사일자
         , to_char(hire_date, 'yyyy-mm-dd hh24:mi:ss') 입사일자2
    from employees;
    
    select employee_id 사원번호
         , first_name || ' ' || last_name 사원명
         , hire_date 입사일자
         , to_char(hire_date, 'yyyy-mm-dd hh24:mi:ss') 입사일자2
    from employees  
    where '05/01/01' <= hire_date AND hire_date'06/12/31';
-- ==  where '2005-01-01 00:00:00' <= to_char(hire_date, 'yyyy-mm-dd hh24:mi:ss) AND to_char(hire_date, 'yyyy-mm-dd hh24:mi:ss) <= '2006-12-31 00:00:00'; 
-- 날짜를 나타낼 때 시,분,초 가 없는 년,월,일만 나타내면 자동적으로 0시 0분 0초가 된다.

 

   select employee_id 사원번호
         , first_name || ' ' || last_name 사원명
         , hire_date 입사일자
         , to_char(hire_date, 'yyyy-mm-dd hh24:mi:ss') 입사일자2
    from employees  
    where '05/01/01' <= hire_date AND hire_date < '07/01/01';