Oracle Trunc functions

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;--sy Sdate and Trunc (sysdate) are not the same sysdate at zero of the day 0 minutes 0 seconds equals trunc (sysdate) Select Trunc (sysdate, ' DD '), Trunc (sysdate) from dual t; --Today 201,407,030 time 0 minutes 0 seconds Select To_char (trunc (sysdate, ' DD '), ' Yyyy/mm/dd hh24:mi:ss '), To_char (Trunc (sysdate), ' yyyy/mm/ DD Hh24:mi:ss ') from Dual;select trunc (The Sysdate-to_date (' 20140709 23:12:12 ', ' yyyy/mm/dd hh24:mi:ss ')) from dual t;--  Two dates difference in days select Trunc (sysdate-1) from dual t;--yesterday select Trunc (sysdate+1) from dual t;--tomorrow Select Trunc (sysdate, ' yy ') from dual;--First day Select Trunc (sysdate, ' year ') from dual;--the first day of the year select Trunc (sysdate, ' yyyy ') from dual;--the first day of the year select Trunc ( Sysdate, ' Q ') from the first day of the quarter on which the current time is dual;--select Trunc (sysdate, ' mm ') from dual;--the first day of the month select Trunc (sysdate, ' month ') from D ual;--the first day of the month select Trunc (sysdate, ' d ') from dual;--returns the first day of the week (Sunday for the first day) Select Trunc (sysdate, ' days ') from dual;-- Returns the first day of the week (Sunday for the first day) Select Trunc (sysdate, ' IW ') from dual;--The next day of the week (Sunday is the first day) Select Trunc (sysdate, ' hh ') from dual; --current time, accurate to hours select Trunc (sysdate, ' hh24 ') from dual;--current time, accurate to hours select Trunc (sysdate, ' mi ') from dual;--current time, accurate to minutes No precision to seconds
/*trunc (number,num_digits) number requires a truncated rounding. The num_digits is used to specify the number of rounding precision. The default value for Num_digits is 0. Positive number is truncated, negative forward intercept trunc () function interception without rounding */select trunc (123.458) from dual; --123select trunc (123.458, 0) from dual; --123select trunc (123.458, 1) from dual; --123.4select trunc (123.458,-1) from dual; --120select trunc (123.458,-4) from dual; --0select trunc (123.458, 4) from dual; --123.458select trunc (123) from dual; --123select trunc (123, 1) from dual; --123select trunc (123,-1) from dual; --120


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.