📜  oracle sysdate - SQL (1)

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

Oracle Sysdate - SQL

Oracle SYSDATE is a function that returns the system date and time of the server where the database is installed. It is used to get the current date and time from the server which can be used in various SQL queries.

Syntax

The syntax of the SYSDATE function is:

SELECT SYSDATE FROM dual;

Output:

| SYSDATE | |---------| | 23-JUN-21 12.13.15 AM |

Usage

SYSDATE can be used in various SQL queries such as:

Fetch current date and time
SELECT SYSDATE FROM dual;
Add/subtract date and time
SELECT SYSDATE + 1 FROM dual; -- adds one day to the current date
SELECT SYSDATE - 1/24 FROM dual; -- subtracts one hour from the current time
Date comparisons
SELECT * FROM orders WHERE order_date > SYSDATE-7; -- fetches orders placed in the last 7 days
Conclusion

In summary, SYSDATE is a very useful function in Oracle SQL for fetching the current date and time, performing date and time arithmetic, and for date comparisons.