Oracle date functions

Source: Internet
Author: User

The Oracle date function is used to process the date and time in the Oracle database. The following describes the usage of the Oracle date function in detail.

1) SYSDATE and TRUNC

The two Oracle date functions take the date of the Oracle server system and cut off the decimal part. Observe the following operations:

Create table test_date (name varchar2 (20), p_date date );

Insert into test_date values ('name1', sysdate );

Select * from test_date;

Select * from test_date where p_date = '25-October-05 ';

Select * from test_date where trunc (p_date) = '25-October-05 ';
In Oracle, SYSDATE is used to obtain time information that not only contains the date, but also contains the time information. The time information is actually the fractional part of the number of vertices.

2) ADD_MONTHS

The Oracle date function returns a date with a month difference from the provided date. The function provides the number of months in the future or before. Syntax:

ADD_MONTHS start date, increase or decrease the number of months)

Select add_months ('26-October-05 ', 2) from dual;

Select add_months ('26-October-05 ',-2) from dual;
3) LAST_DAY

Returns the last day of the month that contains the given date. Syntax:

LAST_DAY (date)

Select last_day ('21-September-80') from dual;
4) MONTHS_BETWEEN

Returns the month of the two-day period. Syntax:

MONTHS_BETWEEN: Latest date, earlier date)

Select months_between ('12-October-05 ', '12-September-03') from dual;
 
 

Learn about Oracle Text Functions

Syntax for creating an Oracle package

Use of Oracle to_char Functions

Implementation of oracle function return table

How to uninstall an Oracle database in Windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.