select trunc(sysdate,'mm') from dual;
SELECT TRUNC(SYSDATE) today,
hiredate,
TO_CHAR(TRUNC(MONTHS_BETWEEN(SYSDATE,hiredate)/12))
|| ' years ' ||
TO_CHAR(MOD(TRUNC(MONTHS_BETWEEN(SYSDATE,hiredate)),12))
|| ' months ' ||
TO_CHAR(TRUNC(SYSDATE) -ADD_MONTHS(hiredate,TRUNC(MONTHS_BETWEEN(SYSDATE,hiredate))))
|| ' days' "Experience"
FROM emp;
hiredate,
TO_CHAR(TRUNC(MONTHS_BETWEEN(SYSDATE,hiredate)/12))
|| ' years ' ||
TO_CHAR(MOD(TRUNC(MONTHS_BETWEEN(SYSDATE,hiredate)),12))
|| ' months ' ||
TO_CHAR(TRUNC(SYSDATE) -ADD_MONTHS(hiredate,TRUNC(MONTHS_BETWEEN(SYSDATE,hiredate))))
|| ' days' "Experience"
FROM emp;
使用到得oracle 时间函数:trunc;add_months;months_between
查询结果 如下
-------------------------------
1 2010-1-26 1980-12-17 29 years 1 months 9 days
2 2010-1-26 1981-2-20 28 years 11 months 6 days
3 2010-1-26 1981-2-22 28 years 11 months 4 days
4 2010-1-26 1981-4-2 28 years 9 months 24 days
5 2010-1-26 1981-9-28 28 years 3 months 29 days
6 2010-1-26 1981-5-1 28 years 8 months 25 days
7 2010-1-26 1981-6-9 28 years 7 months 17 days
8 2010-1-26 1987-4-19 22 years 9 months 7 days
2 2010-1-26 1981-2-20 28 years 11 months 6 days
3 2010-1-26 1981-2-22 28 years 11 months 4 days
4 2010-1-26 1981-4-2 28 years 9 months 24 days
5 2010-1-26 1981-9-28 28 years 3 months 29 days
6 2010-1-26 1981-5-1 28 years 8 months 25 days
7 2010-1-26 1981-6-9 28 years 7 months 17 days
8 2010-1-26 1987-4-19 22 years 9 months 7 days
本文转自 randy_shandong 51CTO博客,原文链接:http://blog.51cto.com/dba10g/270710,如需转载请自行联系原作者