12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using Pseudocolumns, Sequences, and <strong>SQL</strong> Functions6.5.6 Using Date Functions<strong>Oracle</strong> Database provides various functions for calculating and converting datetimedata.See Also: <strong>Oracle</strong> Database <strong>SQL</strong> Reference for details about the datefunctionsPerforming Date Arithmetic<strong>Oracle</strong> Database provides a number of features to help with date arithmetic, so thatyou do not need to perform your own calculations on the number of seconds in a day,the number of days in each month, and so on. Some useful features include thefollowing:■■■■■■■■ADD_MONTHS function, which returns the date plus the specified number ofmonths.MONTHS_BETWEEN function, which returns the number of months between twodates.SYSDATE function, which returns the current date and time set for the operatingsystem on which the database resides.SYSTIMESTAMP function, which returns the system date, including fractionalseconds and time zone, of the system on which the database resides.TRUNC function, which when applied to a DATE value, trims off the time portionso that it represents the very beginning of the day (the stroke of midnight). Bytruncating two DATE values and comparing them, you can determine whetherthey refer to the same day. You can also use TRUNC along with a GROUP BY clauseto produce daily totals.Arithmetic operators such as + and -. For example, SYSDATE-7 refers to 7 daysbefore the current system date.INTERVAL data types, which enable you to represent constants when performingdate arithmetic rather than performing your own calculations. For example, youcan add or subtract INTERVAL constants from DATE values or subtract two DATEvalues and compare the result to an INTERVAL.Comparison operators such as >,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!