Oracle's trunc Function usage example

Source: Internet
Author: User
Select To_char (sysdate, ' yyyy-mm-dd hh24:mi:ss '), To_char (Trunc (sysdate), ' Yyyy-mm-dd Hh24:mi:ss ') from dual T;--sysdate and Trunc (sysdate) are not the same sysdate on the day of zero 0 minutes 0 seconds equals trunc (sysdate) Select Trunc (sysdate, ' DD '), Trunc (Sysdate) FR Om dual T; --Today at 201,407,030, 0 minutes, 0 seconds, select To_char (trunc (sysdate, ' DD '), ' Yyyy/mm/dd hh24:mi:ss '), To_char (Trunc (sysdate), ' yy  
      
      
Yy/mm/dd Hh24:mi:ss ') from dual; Select Trunc (sysdate-to_date (' 20140709 23:12:12 ', ' yyyy/mm/dd hh24:mi:ss ')) from dual t;--the number of days between two dates select Trunc ( sysdate-1) from dual t;--yesterday select Trunc (sysdate+1) from dual t;--tomorrow Select Trunc (sysdate, ' yy ') from dual;-- The first day of select Trunc (Sysdate, ' year ') from dual;--, the first day of select Trunc (sysdate, ' yyyy ') from dual;--the first day of the year select TR  UNC (sysdate, ' Q ') from dual;--the first day of the quarter on which the current time is located select Trunc (sysdate, ' mm ') from dual;--the first day of the month select Trunc (sysdate, ' Month ') from dual;--the first day of the month select Trunc (sysdate, ' d ') from dual;--Returns the first day of the week (Sunday is the first day) Select Trunc (sysdate, "Day") from dual;--returns the first day of the week (Sunday is the first) select Trunc (sysdate, ' IW ') from dual --the second day of this week (Sunday is the first day) Select Trunc (sysdate, ' hh ') from dual; --current time, accurate to hour select Trunc (sysdate, ' hh24 ') from dual;--current time, accurate to hour select Trunc (sysdate, ' mi ') from dual;--current time, Accurate to minute accuracy without precision to second
  
/* TRUNC (number,num_digits)   
number requires a truncated integer.   
num_digits is used to specify the number of rounding precision. The default value for Num_digits is 0.  
a positive number is intercepted, and a negative number is intercepted  
forward TRUNC () function is intercepted without rounding/  
select TRUNC (123.458) from dual;--123  
Select TRUNC (123.458, 0) from dual;  
Select Trunc (123.458, 1) from dual;--123.4  
Select Trunc (123.458,-1) from dual;--120  
Select Trunc (123.45 8,-4) from dual; --0  
Select Trunc (123.458, 4) from dual;--123.458  
select Trunc (123) from dual;--123  
Select Trunc (123, 1) F ROM dual; --123  
Select Trunc (123,-1) from dual;--120

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.