Pole share posted on 2015-11-05-16:54 1/440
45 Very useful Oracle query statementsJust look at the floor of the landlord. Here we introduce a very useful Oracle query statement, mainly covers the date operation, get the server information, get the execution status, calculate the database size and so on inquiries. 40+ These are the skills that all Oracle developers must have, so collect them quickly.
Date/Time related queries
1. Get the first day of the current month
Run this command to quickly return to the first day of the current month. You can replace "sysdate" with any date value to specify the date of the query.
Copy Code
1 2 3 |
Select TRUNC (sysdate, ' MONTH ') "The" of the "a", "the", "from DUAL;" |
2. Get the last day of the current month
This query is similar to the above statement and takes care of the leap year, so when you have number 29th in February, you will return 29/2. You can replace "sysdate" with any date value to specify the date of the query.
Copy Code
1 2 3 |
Select TRUNC (Last_day (sysdate)) "Last day of the current month" from DUAL; |
3. Get the first day of the current year
The first day of the year is January 1, and this query statement can be used in a stored procedure that requires some calculation of the first day of the current year. You can replace "sysdate" with any date value to specify the date of the query.
Copy Code
1 |
Select TRUNC (Sysdate, ' year ') "year a" from DUAL; |
4. Get the last day of the current year
Similar to the query statement above. You can replace "sysdate" with any date value to specify the date of the query.
Copy Code
1 |
SELECT add_months (TRUNC (Sysdate, ' year ')-1 "Year's last Day" from DUAL |
5. Get the number of days in the current month
This statement is useful to calculate the number of days in the current month. You can replace "sysdate" with any date value to specify the date of the query.
Copy Code