使用日期函数-SQL语言基础

时间:2024-05-15 13:24:54
【文件属性】:

文件名称:使用日期函数-SQL语言基础

文件大小:5.26MB

文件格式:PPT

更新时间:2024-05-15 13:24:54

SQL 基础

使用日期函数 * ROUND('25-JUL-05','MONTH') 01-AUG-05 ROUND('25-JUL-05','YEAR') 01-JAN-06 TRUNC('25-JUL-05','MONTH') 01-JUL-05 TRUNC('25-JUL-05','YEAR') 01-JAN-05 * select round((to_date('25-JUL-05','dd-MON-yy')),'MONTH') from dual; select round((to_date('25-JUL-05','dd-MON-yy')),'year') from dual; select trunc((to_date('25-JUL-05','dd-MON-yy')),'month') from dual; select trunc((to_date('25-JUL-05','dd-MON-yy')),'year') from dual; select trunc(to_date('2005-07-25 10:00:00','yyyy-mm-dd hh24:mi:ss'),'year') from dual; Date Functions (continued) The ROUND and TRUNC functions can be used for number and date values. When used with dates, these functions round or truncate to the specified format model. Therefore, you can round dates to the nearest year or month. Example Compare the hire dates for all employees who started in 1982. Display the employee number, hire date, and month started using the ROUND and TRUNC functions. SQL> SELECT empno, hiredate, 2 ROUND(hiredate, 'MONTH'), TRUNC(hiredate, 'MONTH') 3 FROM emp 4 WHERE hiredate like '%1982'; EMPNO HIREDATE ROUND(HIR TRUNC(HIR --------- --------- --------- --------- 7788 09-DEC-82 01-DEC-82 01-DEC-82 7934 23-JAN-82 01-FEB-82 01-JAN-82


网友评论