2012年5月18日星期五

truncate 与日期

我想trunc(sysdate)可以截取日期的年月日,这样截取到秒应该是支持的,看了以下trunc的文档,
总结如下:
设置环境变量
set NLS_DATE_FORMAT=YYYY-MM-DD HH24:MI:SS
select sysdate x from dual /*+当前时间 */
union all
select trunc(sysdate) from dual /*+取年月日 */
union all
select trunc(sysdate,’yy’) from dual /*+取年 */
union all
select trunc(sysdate,’mm’) from dual /*+取年月 */
union all
select trunc(sysdate,’dd’) from dual /*+取年月日 同trunc(sysdate)*/
union all
select trunc(sysdate,’hh24′) from dual /*+取年月日时 */
union all
select trunc(sysdate,’mi’) from dual /*+取年月日时分 */
union all
select trunc(sysdate,’ww’) from dual
union all
select trunc(sysdate,’w') from dual
union all
select trunc(sysdate,’q') from dual /* 取当前季度 */
union all
select trunc(sysdate,’d') from dual /* 取当前星期,从星期日开始 */
X
———————
2011-05-16 10:7:29
2011-05-16 00:0:00
2011-01-01 00:0:00
2011-05-01 00:0:00
2011-05-16 00:0:00
2011-05-16 10:0:00
2011-05-16 10:7:00
2011-05-14 00:0:00
2011-05-15 00:0:00
2011-04-01 00:0:00
2011-05-15 00:0:00
11 rows selected.
注:
ww 表示Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
2011/1/1是星期六,所以每个星期从星期六开始。
w表示Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.
2011/5/1是星期日,所以这个月每个星期从星期日开始。

没有评论:

发表评论