SQL single-row date functions

Define, syntax and an example with output for

SYSDATE

Returns the current system date of the database system.

Syntax:
SYSDATE
Example:
SELECT SYSDATE FROM db_company
Output:
28-May-2010


ADD_MONTHS(Date, months_to_add)

Returns the month by adding n months to the month of the date specified.

Syntax:
add_months( date1, n )
Example:
add_months('01-Aug-03', 3)
Output:
01-Nov-03

LAST_DAY(Date)

Returns the last day of the date specified.

Syntax:
LAST_DAY(date1)
Example:
last_day(to_date('2003/03/15', 'yyyy/mm/dd'))
Output:
Mar 31, 2003

MONTHS_BETWEEN(Date1, Date2)

Returns the number of months between date1 and date2

Syntax:
MONTHS_BETWEEN(date1,date2)
Example:
months_between (to_date ('2003/01/01', 'yyyy/mm/dd'), to_date ('2003/03/01', 'yyyy/mm/dd') )
Output:
2
Subqueries
Subqueries - Explain subqueries with an example, A multiple-row subquery with an example, Single-row subqueries with an example...
SQL*Plus
SQL*Plus - What is SQL*Plus? Explain its features, Explain how to use the SQL*Plus utility, What are the basic SQL*Plus commands?, What is AFIEDT.BUF?, Explain how to enable the SQL*Plus HELP facility...
Oracle database tables
Oracle database tables - What is a Database Table?, How many types of tables supported by Oracle? Explain them, Can you explain how to create a aew table in your schema?, Explain with an example how to create a new table by selecting rows from another table, Depict a sample script for renaming an existing table...
Post your comment

You may like