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