Oracle Numeric Date function

Source: Internet
Author: User

Numeric Functions

the commonly used functions for handling numeric values are as follows :

No.

Function name

meaning

1

Digital  round ( column  |  numbers [. ])

Returns the value after the data is rounded

2

number  trunc ( column  |  Number [. Decimal place ])

data interception, i.e. not rounding

< P>3

Digital  mod ( columns  |  numbers,   Column  |  digital )

for remainder

Date Function

date has three operation formulas :

Date + number = date ( date after n days)

Date – number = date ( date before n days)

Date – date = number (number of days between dates)

Example 1: Displays the date three weeks ago ( days).

Select sysdate-21 from dual;

Example 2: Displays the date after two weeks ( in days).

Select sysdate+14 from dual;

Example 3: Query the number of days that each employee has been hired.

Select Sysdate-hiredate from EMP;

Select Trunc (sysdate-hiredate) from EMP;

Example 4: Query the month and year that each employee has been hired .

Select Trunc (sysdate-hiredate)/30,trunc (sysdate-hiredate)/365 from EMP;

using Angels to achieve year or month calculations must be inaccurate. Oracle provides the following date functions:

No.

Name of function

Meaning

1

Date add_months ( column | date, number of months )

Returns the date after several months of increase

2

Number Months_between ( column | date, column | date )

Returns the number of months between two dates

3

Date last_day ( column | date )

Returns the last day of the month on which the date is

4

Date next_day ( column | date, week X)

Return date in next week, Day of week X

topic 1: the day after 4 months of implementation.

Select Add_months (sysdate,4) from dual;

Topic 2: Query The number of months of employment of EMP all employees so far.

Select Empno,ename,trunc (Months_between (sysdate,hiredate)) from EMP;

Topic 3: Query The last day of the current month .

Select Last_day (sysdate) from dual;

Topic 4: Find out the year of employment for all employees until now.

mode 1: (Date - Date = days)/365--(cannot remove leap year)

Way 2:months_between (sysdate,hiredate)/12

Select Empno,ename,trunc (Trunc (Months_between (sysdate,hiredate))/12) from EMP;

Oracle Numeric Date function

Related Article

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.