Friday, May 3, 2013

Find Experience Number of Years in Oracle

Find  Number of Years Experience in Oracle

                       Oracle supports months_between function which accepts, date1 and date2, & returns number of months.


if date 1 is < date 2 result will be -ve .


SQL> select empno,round(months_between(sysdate,hiredate) /12)||' Yrs' "Exp" from emp;

     EMPNO Exp
---------- --------------------------------------------
      9003 31 Yrs
      7369 32 Yrs
      7499 32 Yrs
      7521 32 Yrs
      7566 32 Yrs
      7654 32 Yrs
      7698 32 Yrs
      7782 32 Yrs
      7788 26 Yrs
      7839 31 Yrs
      7844 32 Yrs

     EMPNO Exp
---------- --------------------------------------------
      7876 26 Yrs
      7900 31 Yrs
      7902 31 Yrs
      7934 31 Yrs
      1011 18 Yrs
      1012 19 Yrs

17 rows selected.

No comments:

Post a Comment