Oracle trunc Function

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 different. sysdate at 00:00:00 of the current day is equal to trunc (sysdate) select trunc (sysdate, 'dd'), trunc (sysdate) from dual t; -- today, 20140703 00:00:00 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 (sysdate-to_date ('2017 23:12:12 ', 'yyyy/mm/dd hh24: mi: ss') from dual t; -- 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 that year select trunc (sysdate, 'Year ') from dual; -- select trunc (sysdate, 'yyyy') from dual; -- select trunc (sysdate, 'q') from dual on the first day of the current year; -- select trunc (sysdate, 'mm') from dual; -- select trunc (sysdate, 'month') from dual on the first day of the month; -- select trunc (sysdate, 'D') from dual on the first day of the month; -- 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 day) select trunc (sysdate, 'iw') from dual; -- the second day of the 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, not accurate to second
 
/* TRUNC (number, num_digits) Number must be rounded to the end. Num_digits is used to specify the number to take an integer. The default value of Num_digits is 0. Forward TRUNC () function is truncated without rounding */select trunc (123.458) from dual; -- 123 select trunc (123.458, 0) from dual; -- 123 select trunc (123.458, 1) from dual; -- 123.4 select trunc (123.458,-1) from dual; -- 120 select trunc (123.458,-4) from dual; -- 0 select trunc (123.458, 4) from dual; -- 123.458 select trunc (123) from dual; -- 123 select trunc (123, 1) from dual; -- 123 select trunc (123,-1) from dual; -- 120

 


 

Related Article

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.