(1) clipping function --TRUNC () Usage
SELECT TRUNC (789.652) fractional interception, TRUNC (789.652,2) taken two decimal places, TRUNC (789.652, -2) rounding
FROM dual ;
(2) query employee number, employee name, hire date:
Not using clipping function TRUNC ():
SELECT empno employee number, ename employee name, hiredate hire date,
(MONTHS_BETWEEN (sysdate, hiredate)) the total number of months of employment,
the total number of years (MONTHS_BETWEEN (sysdate, hiredate) / 12) hire
FROM emp;
Note : sysdate time of the current system, hiredate employee hired period. SELECT empno employee number, ename employee name, hiredate hire date, behind the letters is an alias.
Using a clipping function TRUNC ();
SELECT empno employee number, ename employee name, hiredate hire date,
TRUNC (MONTHS_BETWEEN (sysdate, hiredate)) the total number of months of employment,
TRUNC (MONTHS_BETWEEN (sysdate, hiredate) / 12) the total number of years of employment
FROM emp;
(3) query the emp table all employees hired in 1981, or May 1987 hired employees
A statement:
select * from emp
where hiredate between to_date('1981-1-1','yyyy-mm-dd')
and to_date('1981-12-31','yyyy-mm-dd')
or
hiredate between to_date('1987-5-1','yyyy-mm-dd')
and to_date('1987-5-31','yyyy-mm-dd')
;
Statement II:
select * from emp
where to_char(hiredate,'yyyymmdd') like '1981%'
or to_char(hiredate,'yyyymmdd') like '198705%'
;
Statement three:
select * from emp
where to_char(hiredate,'yyyymmdd') like '1981%'
or to_char(hiredate,'yyyymmdd') like '198705%'
;
(4) emp table displays only the year and month Year
select empno,ename,job,mgr,to_char(hiredate,'yyyy-mm'),sal,comm,deptno from emp;
Note : to_char is used to modify the time format.