-
oracle 날짜함수, 변환함수, decode, caseDataBase/oracle 2020. 3. 15. 19:321234567891011121314151617181920212223242526272829303132333435363738-- sysdate() 현재 시스템의 날짜select sysdate from dual; -- 20/03/15-- months_between(data1, data2) 두개의 파라미터를 이용하여 두 날짜 사이의 개월수 계산select first_name, last_name, months_between(sysdate, hire_date) from employees where department_id = 50;-- add_months() 현재 날짜에서 7개월 더하기select add_months(sysdate, 7) from dual; -- 20/10/15-- next_day() 오늘부터 가장 가까운 해당일select next_day(sysdate, '일요일') from dual; -- 20/03/22-- last_day() 해당 달의 마지막 일수select last_Day(sysdate) from dual; -- 20/03/31-- to_char() data타입을 char타입으로select to_char(sysdate, 'yyyy-mm-dd') from dual; -- 2020-03-15-- to_date() char타입을 dataselect to_Date('2020/03/04', 'yyyy/mm/dd') from dual; -- 2020-03-15-- nvl() null 값을 다른 데이터로 변경하는 함수select first_name, last_name, nvl(commission_pct, 0) from employees order by commission_pct; -- commission_pct 가 null 인 경우 0으로 출력!--decode() switch문과 같은 역할을 함select department_id, decode(department_id, 20, '마켓팅부', 60, '전산부', 90, '경영부', '부서') from employees;-- department_id 를 출력할건데 20은 마켓팅부 60은 전산부 90은 경영부 나머지는 부서로 출력하겠다-- case() if문과 같은 역할select first_name , department_id ,case when department_id = 20 then '마켓팅부'when department_id = 60 then '전산실'when department_id = 90 then '경영부'else ''end "부서명"from employeesorder by department_id;http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
nvl() 을 where절에서 쓰는 경우가 안나와서 아쉬움.. where절에서 쓰일 때가 아직 이해가 잘 안된당..
case() 문을 쓸 때는
case when 조건 then 결과
...
else 결과
end
** decode() 결과
**case() 결과
'DataBase > oracle' 카테고리의 다른 글
oracle join (0) 2020.03.16 oracle group by , having , rollup (0) 2020.03.15 oracle 문자형 함수 (0) 2020.03.15 oracle 숫자형 함수 (0) 2020.03.15 Select (0) 2020.03.10