SQL Tutorial SQL Advanced SQL Database SQL References

Oracle SYSDATE Function



The Oracle (PL/SQL) SYSDATE function returns the current date and time set for the operating system on which the database resides. The datatype of the returned value is DATE, and the format returned depends on the value of the NLS_DATE_FORMAT initialization parameter. The function requires no arguments. In distributed SQL statements, this function returns the date and time set for the operating system of the local database.

Note: This function can not be used in the condition of a CHECK constraint.

Syntax

SYSDATE

Parameters

No parameter is required.

Return Value

Returns the current date and time set for the operating system on which the database resides.

Example 1:

The example below shows the usage of SYSDATE function.

SYSDATE
Result: '27-DEC-2021 05:11:57'

Example 2:

The example below illustrates how to use the NLS_DATE_FORMAT to change the format of the result:

ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24.MI.SS';
SELECT SYSDATE FROM DUAL;

Result: 
SYSDATE
--------------------
29-MAY-2000 13.14.03


ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
SELECT SYSDATE FROM DUAL;

Result: 
SYSDATE
--------------------
29-MAY-2000 13:14:03

Example 3:

Consider a database table called Employee with the following records:

EmpIDNameAgeDate_of_Joining
1John2525-MAY-2018 09:20:38
2Marry2415-OCT-2018 09:21:05
3Jo2709-JUN-2019 09:24:35
4Kim3021-SEP-2019 09:25:24
5Ramesh2825-OCT-2019 09:27:16

To insert a new record in this table, the following statement can be used.

INSERT INTO Employee 
VALUES (6, 'Suresh', 28, SYSDATE);

-- see the result
SELECT * FROM Employee;

This will produce a result similar to:

EmpIDNameAgeDate_of_Joining
1John2525-MAY-2018 09:20:38
2Marry2415-OCT-2018 09:21:05
3Jo2709-JUN-2019 09:24:35
4Kim3021-SEP-2019 09:25:24
5Ramesh2825-OCT-2019 09:27:16
6Suresh2826-DEC-2021 09:28:19

❮ Oracle Functions