SQL> alter session set nls_language = american;

   SQL> select sysdate, hiredate, months_between(sysdate, hiredate), add_months(hiredate, 6)

from emp;


   SQL> select next_day(sysdate, 'Sat'), next_day(sysdate, 'wed')

from dual;

  

   SQL> select last_day('2011-02-11'), last_day('2016-02-21')

from dual;


   SQL> select  sysdate, next_day(add_months(sysdate, 6), 'fri')

from dual;



  * Single-Row functions

   SQL> select sysdate, hiredate, sysdate - hiredate, ceil(sysdate - hiredate)

from emp;



  * ROUND, TRUNC

   SQL> select sysdate, round(sysdate, 'month'), round(sysdate, 'year') from dual;

   SQL> select to_date('2011-12-15'), round(to_date('2011-12-15'), 'month') from dual;


   SQL> select hiredate, trunc(hiredate, 'Month'), trunc(hiredate, 'Year') from emp;

   SQL> select empno, ename, hiredate from emp where trunc(hiredate, 'Month') = '1981-02-01';   --> 1981년 2월 입사자


↑ ↑ ↑


cf.) SQL> select empno, ename, hiredate

         from emp

 where hiredate between to_date('1981-02-01') and to_date('1981-02-28');


   SQL> select empno, ename, hiredate from emp where trunc(hiredate, 'Year')  = '1982-01-01';   --> 1982년 입사자



'Oracle > SQL Fundamentals I' 카테고리의 다른 글

6일차 # Implicit conversion * 3-27 :For assignment  (0) 2012.04.10
6일차 Conversion  (0) 2012.04.10
5일차 # 3-20: Date 산술연산  (0) 2012.04.09
5일차 # 3-17: Working with Dates  (0) 2012.04.09
5일차 Date #3-19: DUAL table  (0) 2012.04.09

+ Recent posts