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