I. Demand
Current time: 2018-1-6 16:56:01
Because of the data in the database at the beginning of last year, that is (2017-1-1 00:00:00) and the end of last year (2017-12-31 23:59:00), the two time periods: ii. results
1, obtain early last year (2017-1-1 00:00:00) (>=) and the beginning of this year (2018-1-1 00:00:00) (can use less than <);
The SQL statement is as follows:
SELECT (TRUNC (sysdate, ' YYYY ')-interval ' 1 ' year), (TRUNC (sysdate, ' YYYY ')] from dual;
2. Access to the beginning of last year (2017-1-1-00:00:00) and the end of (2017-12-31-23:59:00)
Sql:
SELECT (TRUNC (sysdate, ' YYYY ')-interval ' 1 ' year), (TRUNC (sysdate, ' YYYY '))-interval ' 1 ' MINUTE from dual;
Referencing block contents
3. Get the month of last year (2017-1-1 00:00:00) (with >= number) and the end of (2017-2-1 00:00:00) (with <)
Sql:
SELECT (TRUNC (sysdate, ' mm ')-interval ' 1 '), Add_months ((TRUNC (sysdate, ' mm ')-interval ' 1 ' year), 1) from dual;
Third, Summary:
1, TRUNC (sysdate, ' format '): Format can write ' YYYY ', ' MM ', ' DD ' etc, to get different initial value;
2, can combine minus a "INTERVAL ' 1 ' Year", "INTERVAL ' 1 ' MONTH", "INTERVAL ' 1 ' Day" to precisely adjust;
3, you can use the Last_day () method to obtain the last day of the month, also can be obtained by the beginning of last month, minus 1 days;
4, Trunc seems to be accurate only to minutes, not to seconds, this is not sure, there is no big God knows how accurate to the second.