0% found this document useful (0 votes)
111 views8 pages

Numeric Functions in SQL

The document describes various numeric and string functions in SQL. Numeric functions include ABS, POWER, ROUND, SQRT, EXTRACT, GREATEST, LEAST, MOD, TRUNC, FLOOR, and CEIL. String functions include LOWER, INITCAP, UPPER, LENGTH, LTRIM, RTRIM, and TRIM. These functions perform mathematical and string operations like calculating absolute values, exponents, rounding numbers, extracting date parts, finding greatest/least values, truncating decimals, and modifying string cases and lengths.

Uploaded by

Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views8 pages

Numeric Functions in SQL

The document describes various numeric and string functions in SQL. Numeric functions include ABS, POWER, ROUND, SQRT, EXTRACT, GREATEST, LEAST, MOD, TRUNC, FLOOR, and CEIL. String functions include LOWER, INITCAP, UPPER, LENGTH, LTRIM, RTRIM, and TRIM. These functions perform mathematical and string operations like calculating absolute values, exponents, rounding numbers, extracting date parts, finding greatest/least values, truncating decimals, and modifying string cases and lengths.

Uploaded by

Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Numeric Functions in SQL

Mathematical Functions
ABS: Returns the absolute value of ‘n’

Select ABS(-15) from dual;

Select ABS(-15) “Absolute” from dual;

Power: Returns m raised to the nth power. N must be an integer.


POWER(m,n)

Select Power(3,2) from Dual;

Round: Returns n rounded to m places

ROUND(n[,m])
Select ROUND (15.19,1) “Round” from dual;
SQRT: Returns square root of n.

SQRT(n)

Select sqrt(5) from dual;

EXTRACT: Returns a value extracted from a date or an interval value.

select extract (year from date '2017-09-09') "YEAR" from dual;

select extract (month from sysdate) from dual;

EXTRACT(MONTHFROMSYSDATE)
-------------------------
9
GREATEST: Returns the greatest value in the list of expressions.

GREATEST(expr1, expr2….exprn)

select greatest(4,5,17) from dual;

GREATEST(4,5,17)
----------------
17

select greatest('4','5','17') from dual;

G
-
5
LEAST: Returns the least value in the list of expressions.

LEAST(expr1, expr2, ….., exprn)

Select LEAST(4,5,17) from dual;

MOD: Returns the remainder of first number divided by second number.

MOD(m,n)

Select MOD(15,7) from dual;

TRUNC: returns a number truncated to a certain number of decimal places.

TRUNC(n[,decimal places])
Select TRUNC(125.815,1) from dual;
FLOOR: Returns the largest integer value that is equal to or less than a number.

Select Floor(24.8) from dual //24

Select Floor(13.15) from dual //13

CEIL: Returns the smallest integer value that is greater than a number.

Select Floor(24.8) from dual //25

Select Floor(13.15) from dual //14


STRING FUNCTIONS
LOWER: Returns char, with all letters in lowercase.

Select lower(‘NAME’) from dual;

INITCAP: Returns string, with first letter of each word in Uppercase.

Select INITCAP(‘WHAT IS YOUR NAME’) from dual;

UPPER: Returns char, with all letters in uppercase.


LENGTH: Returns the length of a word.

Select LENGTH(‘String’) from dual;

LTRIM: Removes characters from the left side.

Select LTRIM(‘AJAY’,’A’) from dual; \\JAY

RTRIM: Removes characters from the right side.

TRIM: Removes characters from both side

You might also like