Kim Hyeong
오라클 DB의 날짜 함수 본문
/*sysdate()*/
현재의 날짜를(System) 구해온다
select sysdate from dual;
/*months_between()*/
select first_name, last_name, months_between(sysdate, hire_date)
FROM EMPLOYEES
where department_id = 50;
//2개의 파라미터가 들어간다. 2개를 이용해서 두 날짜 사이의 개월수(차이)를 구해주는 구해준다.
/*add_months()*/
select add_months(sysdate, 7) from dual;
//개월수를 더한다. 현제 3월일 경우 7을 더해 10월이 된다.
/*next_day()*/
select next_day(sysdate, '일요일') from dual;
//다가올 요일에 대한 날짜를 알고 싶을 경우 사용
/*last day()*/
select last_day(sysdate) from dual;
//해당달의 마지막 일수를 구하는 함수
/*to_char()*/
select to_char(sysdate, 'yyyy/mm/dd') from dual;
//sysdate를 문자열로 변환
/*to_date()*/
select to_date('2015/03/04','yyyy/mm/dd') from dual;
//문자열 데이터를 날짜로 바꾼다.
/*nvl(): 널값을 다른 데이터로 변경하는 함수*/
select * from EMPLOYEES;
select first_name, last_name, nvl(commission_pct, 0) commission from EMPLOYEES;
/*decode(): switch문의 역할을 하는 함수*/
select * from DEPARTMENTS;
select department_id, decode(department_id, 20, '마케팅부', 60, '전산', 90,'경영부', '부서')
from EMPLOYEES;
/*case() : elseif문과 같은 역할 함수*/
select first_name, department_id,
case when department_id = 20 then '마케팅부'
when department_id = 60 then '전산실'
when department_id = 90 then '경영부'
else ''
end "부서명"
from EMPLOYEES;