반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | /* 날짜 함수 */ /* sysdate() : 현재날짜 (system의 날짜) */ select sysdate from dual; /* months_between(date1-최근날짜,date2-이전날짜) */ select first_name, last_name, months_between(sysdate,hire_date) from employees where department_id = 50; /* 두 날짜 사이의 개월수 차이 (고용일부터 현재까지)*/ /* add_months() */ select add_months(sysdate, 4) -- 개월수를 더함 from dual; /* next_day() */ select next_day(sysdate,'일요일') -- 다가올 일요일에 해당하는 날짜 from dual; 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; select to_char(sysdate, 'yy/mm/dd') from dual; /* to_date() */ select to_date('2015/03/03', 'yyyy/mm/dd') -- 문자열을 날짜형태로 바꿈 from dual; /* nvl() : null값을 다른 데이터로 변경하는 함수 */ select first_name, last_name, nvl(commission_pct, 0) commission from employees; /* decode() : switch문의 역할을 하는 함수 */ select department_id, decode(department_id, 20, '마케팅부', 60, 'IT', 90, '경영','부서') from employees; /* case() : else if 문과 같은 역할을 하는 함수 */ select first_name, department_id case when department_id = 20 then 'marketing' when departmnet_id = 60 then '전산실' when department_id = 90 then '경영' else 'Others' and "부서명" from employees; | cs |
반응형
'프로그래밍 > SQL' 카테고리의 다른 글
[Oracle SQL] Join (0) | 2017.08.08 |
---|---|
[Oracle SQL] GROUP BY, HAVING, ROLLUP (0) | 2017.08.08 |
[Oracle SQL] 숫자함수 (0) | 2017.08.04 |
[Oracle SQL] 문자 함수 (0) | 2017.08.03 |
[Oracle SQL] Select 문 And,OR, NOT, BETWEEN (0) | 2017.07.29 |