trunc函數的用法

trunc用於截取數字和日期。函數

1.截取數字spa

trunc(n1,n2),n1表示被截斷的數字,n2表示要截斷到那一位。n2能夠是負數,表示截斷小數點前.date

1. select trunc(34.245) from dual; --34select

2. select trunc(34.245,1) from dual; --34.2
3. select trunc(34.245,-1) from dual; --30
時間

2.截取日期co

1.select trunc(sysdate) from dual  --2017-10-13  今天的日期爲2017-10-13
2.select trunc(sysdate, 'mm')   from   dual  --2017-10-1    返回當月第一天.
3.select trunc(sysdate,'yy') from dual  --2017-1-1       返回當年第一天
4.select trunc(sysdate,'dd') from dual  --2017-10-13    返回當前年月日
5.select trunc(sysdate,'yyyy') from dual  --2017-1-1   返回當年第一天
6.select trunc(sysdate,'d') from dual  --2017-10-8 (星期日)返回當前星期的第一天
7.select trunc(sysdate, 'hh') from dual   --2017-10-13 17:00:00   當前時間爲17:31
8.select trunc(sysdate, 'mi') from dual  --2017-10-13 17:31:00   TRUNC()函數沒有秒的精確數字

相關文章
相關標籤/搜索