ORACLE LAB 3
FUNCTIONS
SQL Functions
SQL functions are built into Oracle
The functions can be used to perform the
following:
◦ Perform complex calculation on data
◦ Modify individual data items
◦ Modify output for a group of rows
◦ Alter formats for display including date
formats
Types of function
Single row functions
◦ Number functions
◦ Character functions
◦ Date Time functions
◦ Conversion functions
◦ General functions
Group functions or Aggregate functions
Number functions
ABS(n)
CEIL(n)
FLOOR(n)
MOD(m,n)
POWER(m,n)
SIGN(n)
SQRT(n)
TRUNC(m,[n])
ROUND (m,[n])
ABS(n)
Thisfunction returns the
magnitude(absolute value) of n
select ABS(-87) from dual;
Dual – is a null table used to test various sql
commands
CEIL (n)
This function finds the smallest integer
greater than or equal to n
select CEIL(87), CEIL(87.3), CEIL(-87.1)
from dual;
FLOOR(n)
This integer finds the largest integer less
than or equal to the value of n
select FLOOR(87), FLOOR(87.3),
FLOOR(-87.1) from dual;
MOD (m,n)
This function returns the remainder of m
divided by n. It returns m if n = 0.
select mod(15,4), mod(3,4) from dual;
POWER (m,n)
Thisfunction returns m raised to the
power of n
select power(2,4) from dual;
SQRT(n)
This function returns the square root of n.
If n is null then the result is NULL. The
value of n should always be positive.
select SQRT (20), SQRT(9) from dual;
TRUNC (m,[n])
This function truncates m to n decimal
places. If n is omitted then it is truncated
to no decimal places.
If n is negative than the numbers left to
the decimal point are truncated to 0
select TRUNC (91.783,1), TRUNC
(91.783,2), TRUNC (91.783,0), TRUNC
(91.783,-2) from dual;
ROUND (m,[n])
This function rounds m to n decimal
places. If n is omitted it is rounded to no
decimal places. If n is negative, numbers
left of the decimal point are rounded
select round(91.783,1), round(91.783,-1),
round (91.783) from dual ;
Character Function returning character
CHR(x)
CONCAT(string1,string2)
INITCAP(string)
LOWER(string)
UPPER(string)
LPAD(char1,n[,char2]))
RPAD(char1,n[,char2]))
LTRIM(string, ‘char\s’)
RTRIM(string, ‘char\s’)
TRIM(string2 from string1)
SUBSTR(string,m[,n])
REPLACE(String, search_str[,replace_str])
TRANSLATE(string, from_str, to_str)
CHR(x)
This function returns the character that
has the value equivalent to x in the
database character set
select chr(121) from dual;
CONCAT(string1,string2)
This function returns string1 concatenated
with string2
Select concat(‘ABC’,’DEF’) from dual;
INITCAP(string)
This function capitalizes the first
character of each word in the string
select INITCAP(‘my name is manas
mukul’) from dual;
LOWER(string)
This function converts the string to lower
case
select LOWER(‘MY NAME IS MANAS
Mukul’) from dual;
UPPER(string)
This function converts the string to upper
case
select UPPER(‘my name is Manas Mukul’)
from dual;