📜  oracle sysdate - 1 个月 - SQL (1)

📅  最后修改于: 2023-12-03 15:03:24.069000             🧑  作者: Mango

Oracle Sysdate - 1 Month - SQL

In Oracle, SYSDATE is a function that returns the current system date and time. It is commonly used in SQL queries to filter or order data by date.

To subtract one month from the current date, you can use the ADD_MONTHS function, which takes two arguments: the original date and the number of months to add or subtract. To subtract one month, you can pass -1 as the second argument.

Here is an example SQL query that uses SYSDATE and ADD_MONTHS to select data from the previous month:

SELECT *
FROM my_table
WHERE my_date >= ADD_MONTHS(SYSDATE, -1)
AND my_date < SYSDATE;

In this example, my_table is the name of the table you want to query, and my_date is the name of the column that contains the date values you want to filter by. The first condition (my_date >= ADD_MONTHS(SYSDATE, -1)) selects all rows where my_date is greater than or equal to the first day of the previous month. The second condition (my_date < SYSDATE) selects all rows where my_date is less than the current date.

You can modify this query to suit your needs, such as by selecting specific columns or using additional filtering conditions.

In conclusion, using SYSDATE and ADD_MONTHS in your SQL queries can help you perform date calculations and filtering with ease in Oracle.