Operators Operators & & Functions Functions
Operators Operators & & Functions Functions
&
Functions
Operators
Arithmetic operator
Logical operator
Comparison operator
Type Symbol / Keyword Where to use
Arithmetic operators +, -, *, /
Operator precedence *, /, +, -
Types
Character functions
Numeric functions
Date functions
Conversion functions
Character Functions
Syntax Description
Syntax Description
Function Result
INITCAP (‘oracle software’) Oracle Software
LOWER (‘ORACLE Software’) Oracle software
UPPER (‘Oracle Software’) ORACLE SOFTWARE
LTRIM ( ‘ Oracle’,’ ‘ ) Oracle
RTRIM (‘Oracle’,’e’) Oracl
TRANSLATE('223abcd', '0123abc', 886XYZd
'9786XYZ')
REPLACE('JACK and JUE','J','BL') BLACK and BLUE
Examples for Character Functions
Function Result
SUBSTR('ABCDEFG',3,3) CDE
chr(65) A
length(‘oracle’) 6
Numeric Functions:
Syntax Description
abs ( ) Returns the absolute value
ceil ( ) Rounds the argument
cos ( ) Cosine value of argument
exp ( ) Exponent value
floor( ) Truncated value
power (m,n) N raised to m
mod (m,n) Remainder of m / n
round (m,n) Rounds m’s decimal places to n
trunc (m,n) Truncates m’s decimal places to n
sqrt (m) Square root value
Numeric Functions
Function Result
abs (-15 ) 15
ceil ( 11.7 ) 12
cos (0*3.14/180) 1
exp(4) 54.59815
floor(11.7 ) 11
power (2,3) 8
mod (1000,300) 100
round(15.136,2) 15.14
trunc (15.136,2) 15.13
sqrt (9) 3
Date Functions:
Syntax Description
add_months(date,no. of Return the date after adding the
months) number of months
last_day(date) Returns the last date corresponding to
the last day of the month
months_between(date1,date2) Returns the numeric value of the
difference between the months.
round(date, [format] ) Format – ‘day’, ‘month’ , ‘year’
rounded to the nearest format
specified
next_day(date, day) Returns the next date of the day
trunc(date, [format] ) Format – ‘day’, ‘month’ , ‘year’
Day – previous nearest Sunday
Month – start date of the month
Year – start date of the year
SYSDATE Function
SYSDATE is a date function that returns the current
database server date and time.
Function Result
Add_months(’03-AUG-10‘,3) 03-NOV-10
Last_day(sysdate) 31-AUG-10
Months_between(sysdate,'11-jan-2010') 6.75448066
Next_day('03-AUG-10','wednesday') 10-AUG-10
DATE Functions
Sysdate = 03-Aug-10
Function Result
Round(sysdate,’month’) 01-AUG-10
Round(sysdate,’year’) 01-JAN-11
Trunc(sysdate,’month’) 01-AUG-10
Trunc(sysdate,’year’) 01-JAN-10
Group Functions:
Result based on group of rows.
Group functions operate on sets of rows to give one result per group
Employees
Dept_id Salary
90 5000
The maximum
Max(salary)
90 10000 salary in the
employees 10000
90 10000 table
60 5000
60 5000
Types of Group Functions
Syntax Description
Employees
Dept_id Salary
D_id Avg(Salary)
10 4000 The average
salary in 10 5000
10 5000 employees
table for each 50 4000
10 6000
department
50 5000
50 3000
Select dept_id, avg(salary) from employees group by
dept_id;