SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Built-in Functions in SQL
Numeric Functions
Function Input Argument Value Returned
ABS ( m ) m = value Absolute value of m
MOD ( m, n ) m = value, n = divisor Remainder of m divided by n
POWER ( m, n ) m = value, n = exponent m raised to the nth power
ROUND ( m [, n ] )
m = value, n = number of decimal
places, default 0
m rounded to the nth decimal place
TRUNC ( m [, n ] )
m = value, n = number of decimal
places, default 0
m truncated to the nth decimal place
SIN ( n ) n = angle expressed in radians sine (n)
COS ( n ) n = angle expressed in radians cosine (n)
TAN ( n ) n = angle expressed in radians tan (n)
SQRT ( n ) n = value positive square root of n
EXP ( n ) n = value e raised to the power n
LN ( n ) n > 0 natural logarithm of n
LOG ( n2, n1 )
base n2 any positive value other
than 0 or 1, n1 any positive value
logarithm of n1, base n2
CEIL ( n ) n = value
smallest integer greater than or equal
to n
FLOOR ( n ) n = value
greatest integer smaller than or equal
to n
SIGN ( n ) n = value -1 if n < 0, 0 if n = 0, and 1 if n > 0
SQL Server allows DUAL to be specified as a table in queries that do not need data from any tables.
Here are some examples of the use of some of these numeric functions:
select round (83.28749,2) from dual;
or simply write
select round (83.28749,2);
select sqrt (3.67) from dual;
select power (2.512,5) from dual;
String Functions
Function Input Argument Value Returned
INITCAP ( s ) s = character string
First letter of each word is changed to
uppercase and all other letters are in lower
case.
LOWER ( s ) s = character string All letters are changed to lowercase.
UPPER ( s ) s = character string All letters are changed to uppercase.
CONCAT ( s1, s2 )
s1 and s2 are character
strings
Concatenation of s1 and s2. Equivalent to s1
|| s2
LPAD ( s1, n [, s2] )
s1 and s2 are character
strings and n is an
integer value
Returns s1 right justified and padded left
with n characters from s2; s2 defaults to
space.
RPAD ( s1, n [, s2] )
s1 and s2 are character
strings and n is an
integer value
Returns s1 left justified and padded right
with n characters from s2; s2 defaults to
space.
LTRIM ( s [, set ] )
s is a character string
and set is a set of
characters
Returns s with characters removed up to
the first character not in set; defaults to space
RTRIM ( s [, set ] )
s is a character string
and set is a set of
characters
Returns s with final characters removed after
the last character not in set; defaults to space
REPLACE ( s, search_s
[, replace_s ] )
s = character string,
search_s = target
string, replace_s =
replacement string
Returns s with every occurrence of search_s
in s replaced by replace_s; default removes
search_s
SUBSTR ( s, m [, n ] )
s = character string, m
= beginning position, n
= number of characters
Returns a substring from s, beginning in
position m and n characters long; default
returns to end of s.
LENGTH ( s ) s = character string Returns the number of characters in s.
INSTR ( s1, s2 [, m [, n
] ] )
s1 and s2 are character
strings, m = beginning
position, n =
occurrence of s2 in s1
Returns the position of the nth occurrence of
s2 in s1, beginning at position m, both m and
n default to 1.
Here are some examples of the use of String functions:
select concat ('Alan', 'Turing') as "NAME" from dual;
select 'Alan' || 'Turing' as "NAME" from dual;
select initcap ("now is the time for all good men to come to the aid of the
party") as "SLOGAN" from dual;
select substr('Alan Turing', 1, 4) as "FIRST" from dual;
String / Number Conversion Functions
Function Input Argument Value Returned
TO_CHAR ( m [, fmt ] )
m = numeric value,
fmt = format
Number m converted to character
string as specified by the format
TO_NUMBER ( s [, fmt ] )
s = character string,
fmt = format
Character string s converted to a
number as specified by the format
Formats for TO_CHAR Function
Symbol Explanation
9
Each 9 represents one digit in the
result
0
Represents a leading zero to be
displayed
$
Floating dollar sign printed to the left
of number
L Any local floating currency symbol
. Prints the decimal point
,
Prints the comma to represent
thousands
Group Functions
Function
Input
Argument
Value Returned
AVG ( [ DISTINCT | ALL
] col )
col = column
name
The average value of that column
COUNT ( * ) none
Number of rows returned including
duplicates and NULLs
COUNT ( [ DISTINCT |
ALL ] col )
col = column
name
Number of rows where the value of the
column is not NULL
MAX ( [ DISTINCT | ALL
] col )
col = column
name
Maximum value in the column
MIN ( [ DISTINCT | ALL
] col )
col = column
name
Minimum value in the column
SUM ( [ DISTINCT | ALL
] col )
col = column
name
Sum of the values in the column
Date and Time Functions
Function Input Argument Value Returned
ADD_MONTHS ( d, n )
d = date, n = number of
months
Date d plus n months
LAST_DAY ( d ) d = date
Date of the last day of the
month containing d
MONTHS_BETWEEN (
d, e )
d and e are dates
Number of months by which e
precedes d
NEW_TIME ( d, a, b )
d = date, a = time zone
(char), b = time zone
(char)
The date and time in time zone
b when date d is for time zone a
NEXT_DAY ( d, day ) d = date, day = day of the Date of the first day of the
week week after d
SYSDATE() none Current date and time
GREATEST ( d1, d2, ...,
dn )
d1 ... dn = list of dates Latest of the given dates
LEAST ( d1, d2, ..., dn ) d1 ... dn = list of dates Earliest of the given dates
Try:
SELECT SYSDATE();
SELECT LAST_DAY(SYSDATE());
Date Formats
Format Code Description Range of Values
DD Day of the month 1 - 31
DY Name of the day in 3 uppercase letters SUN, ..., SAT
DAY
Complete name of the day in uppercase,
padded to 9 characters
SUNDAY, ...,
SATURDAY
MM Number of the month 1 - 12
MON
Name of the month in 3 uppercase
letters
JAN, ..., DEC
MONTH
Name of the month in uppercase padded
to a length of 9 characters
JANUARY, ...,
DECEMBER
RM Roman numeral for the month I, ..., XII
YY or YYYY Two or four digit year 71 or 1971
HH:MI:SS Hours : Minutes : Seconds 10:28:53
HH 12 or HH
24
Hour displayed in 12 or 24 hour format 1 - 12 or 1 - 24
MI Minutes of the hour 0 - 59
SS Seconds of the minute 0 - 59
AM or PM Meridian indicator AM or PM
Ad

Recommended

Numeric functions in SQL | Oracle
Numeric functions in SQL | Oracle
Vimal Raj
 
Oracle sql functions
Oracle sql functions
Vivek Singh
 
sql function(ppt)
sql function(ppt)
Ankit Dubey
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
Rai University
 
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Philip Schwarz
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
Rai University
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
Rai University
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
Rai University
 
Functions torage class and array and strings-
Functions torage class and array and strings-
aneebkmct
 
Reasoning about laziness
Reasoning about laziness
Johan Tibell
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
Single row functions
Single row functions
Soumyajit Dutta
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
tmont
 
Clojure basics
Clojure basics
Knoldus Inc.
 
Matlab quickref
Matlab quickref
Arduino Aficionado
 
Matlab practice
Matlab practice
ZunAib Ali
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
Scala categorytheory
Scala categorytheory
Knoldus Inc.
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
String in programming language in c or c++
String in programming language in c or c++
Azeemaj101
 
Applicative Functor - Part 3
Applicative Functor - Part 3
Philip Schwarz
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Philip Schwarz
 
Use Cases of Row Pattern Matching in Oracle 12c
Use Cases of Row Pattern Matching in Oracle 12c
Gerger
 
Handling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4
Randa Elanwar
 
Strings part2
Strings part2
yndaravind
 
Monad Fact #4
Monad Fact #4
Philip Schwarz
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
Randa Elanwar
 
Intro to tsql unit 10
Intro to tsql unit 10
Syed Asrarali
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
DrkhanchanaR
 

More Related Content

What's hot (20)

Functions torage class and array and strings-
Functions torage class and array and strings-
aneebkmct
 
Reasoning about laziness
Reasoning about laziness
Johan Tibell
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
Single row functions
Single row functions
Soumyajit Dutta
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
tmont
 
Clojure basics
Clojure basics
Knoldus Inc.
 
Matlab quickref
Matlab quickref
Arduino Aficionado
 
Matlab practice
Matlab practice
ZunAib Ali
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
Scala categorytheory
Scala categorytheory
Knoldus Inc.
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
String in programming language in c or c++
String in programming language in c or c++
Azeemaj101
 
Applicative Functor - Part 3
Applicative Functor - Part 3
Philip Schwarz
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Philip Schwarz
 
Use Cases of Row Pattern Matching in Oracle 12c
Use Cases of Row Pattern Matching in Oracle 12c
Gerger
 
Handling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4
Randa Elanwar
 
Strings part2
Strings part2
yndaravind
 
Monad Fact #4
Monad Fact #4
Philip Schwarz
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
Randa Elanwar
 
Functions torage class and array and strings-
Functions torage class and array and strings-
aneebkmct
 
Reasoning about laziness
Reasoning about laziness
Johan Tibell
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
tmont
 
Matlab practice
Matlab practice
ZunAib Ali
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
Scala categorytheory
Scala categorytheory
Knoldus Inc.
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
String in programming language in c or c++
String in programming language in c or c++
Azeemaj101
 
Applicative Functor - Part 3
Applicative Functor - Part 3
Philip Schwarz
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Philip Schwarz
 
Use Cases of Row Pattern Matching in Oracle 12c
Use Cases of Row Pattern Matching in Oracle 12c
Gerger
 
Handling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4
Randa Elanwar
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
Randa Elanwar
 

Similar to Built-in Functions in SQL | Numeric Functions (20)

Intro to tsql unit 10
Intro to tsql unit 10
Syed Asrarali
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
DrkhanchanaR
 
Oracle sql ppt2
Oracle sql ppt2
Madhavendra Dutt
 
Structured query language functions
Structured query language functions
Vineeta Garg
 
COIS 420 - Practice 03
COIS 420 - Practice 03
Angel G Diaz
 
Les03
Les03
Vijay Kumar
 
Sql operators & functions 3
Sql operators & functions 3
Dr. C.V. Suresh Babu
 
SQL BUILT-IN FUNCTION
SQL BUILT-IN FUNCTION
Arun Sial
 
Les03
Les03
arnold 7490
 
Les03
Les03
Sudharsan S
 
Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
Achmad Solichin
 
e computer notes - Single row functions
e computer notes - Single row functions
ecomputernotes
 
SQL select statement and functions
SQL select statement and functions
Vikas Gupta
 
Built-Functions in MySqll (Advance Database System)
Built-Functions in MySqll (Advance Database System)
khurtdhangonzales
 
Chapter-5.ppt
Chapter-5.ppt
CindyCuesta
 
Single-Row Functions in orcale Data base
Single-Row Functions in orcale Data base
Salman Memon
 
2 sql - single-row functions
2 sql - single-row functions
Ankit Dubey
 
Function and types
Function and types
Sherin Fathima
 
Les03.pptx
Les03.pptx
NishaTariq1
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
Raviteja Chowdary Adusumalli
 
Intro to tsql unit 10
Intro to tsql unit 10
Syed Asrarali
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
DrkhanchanaR
 
Structured query language functions
Structured query language functions
Vineeta Garg
 
COIS 420 - Practice 03
COIS 420 - Practice 03
Angel G Diaz
 
SQL BUILT-IN FUNCTION
SQL BUILT-IN FUNCTION
Arun Sial
 
Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
Achmad Solichin
 
e computer notes - Single row functions
e computer notes - Single row functions
ecomputernotes
 
SQL select statement and functions
SQL select statement and functions
Vikas Gupta
 
Built-Functions in MySqll (Advance Database System)
Built-Functions in MySqll (Advance Database System)
khurtdhangonzales
 
Single-Row Functions in orcale Data base
Single-Row Functions in orcale Data base
Salman Memon
 
2 sql - single-row functions
2 sql - single-row functions
Ankit Dubey
 
Ad

More from Raj vardhan (20)

Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3
Raj vardhan
 
Internet Basics Unit-7
Internet Basics Unit-7
Raj vardhan
 
Local Area Network – Wired LAN
Local Area Network – Wired LAN
Raj vardhan
 
Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5
Raj vardhan
 
UNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN C
Raj vardhan
 
Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture
Raj vardhan
 
UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices
Raj vardhan
 
Unit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 Complete
Raj vardhan
 
Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2
Raj vardhan
 
Swachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project Report
Raj vardhan
 
Network Topology
Network Topology
Raj vardhan
 
Microsoft Office Word Introduction Complete
Microsoft Office Word Introduction Complete
Raj vardhan
 
Digital money Revolution Introduction
Digital money Revolution Introduction
Raj vardhan
 
C Programming
C Programming
Raj vardhan
 
Definition of Business
Definition of Business
Raj vardhan
 
Business Terms & Concepts
Business Terms & Concepts
Raj vardhan
 
Number System Conversion | BCA
Number System Conversion | BCA
Raj vardhan
 
Interaction With Computers FIT
Interaction With Computers FIT
Raj vardhan
 
FIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCA
Raj vardhan
 
Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205
Raj vardhan
 
Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3
Raj vardhan
 
Internet Basics Unit-7
Internet Basics Unit-7
Raj vardhan
 
Local Area Network – Wired LAN
Local Area Network – Wired LAN
Raj vardhan
 
Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5
Raj vardhan
 
UNIT 4-HEADER FILES IN C
UNIT 4-HEADER FILES IN C
Raj vardhan
 
Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture
Raj vardhan
 
UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices
Raj vardhan
 
Unit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 Complete
Raj vardhan
 
Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2
Raj vardhan
 
Swachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project Report
Raj vardhan
 
Network Topology
Network Topology
Raj vardhan
 
Microsoft Office Word Introduction Complete
Microsoft Office Word Introduction Complete
Raj vardhan
 
Digital money Revolution Introduction
Digital money Revolution Introduction
Raj vardhan
 
Definition of Business
Definition of Business
Raj vardhan
 
Business Terms & Concepts
Business Terms & Concepts
Raj vardhan
 
Number System Conversion | BCA
Number System Conversion | BCA
Raj vardhan
 
Interaction With Computers FIT
Interaction With Computers FIT
Raj vardhan
 
FIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCA
Raj vardhan
 
Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205
Raj vardhan
 
Ad

Recently uploaded (20)

ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
LDM Recording Presents Yogi Goddess by LDMMIA
LDM Recording Presents Yogi Goddess by LDMMIA
LDM & Mia eStudios
 
Tanja Vujicic - PISA for Schools contact Info
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
How to Customize Quotation Layouts in Odoo 18
How to Customize Quotation Layouts in Odoo 18
Celine George
 
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
RAKESH SAJJAN
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
LDMMIA Practitioner Student Reiki Yoga S2 Video PDF Without Yogi Goddess
LDMMIA Practitioner Student Reiki Yoga S2 Video PDF Without Yogi Goddess
LDM & Mia eStudios
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
RAKESH SAJJAN
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
LDM Recording Presents Yogi Goddess by LDMMIA
LDM Recording Presents Yogi Goddess by LDMMIA
LDM & Mia eStudios
 
Tanja Vujicic - PISA for Schools contact Info
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
How to Customize Quotation Layouts in Odoo 18
How to Customize Quotation Layouts in Odoo 18
Celine George
 
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
RAKESH SAJJAN
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
LDMMIA Practitioner Student Reiki Yoga S2 Video PDF Without Yogi Goddess
LDMMIA Practitioner Student Reiki Yoga S2 Video PDF Without Yogi Goddess
LDM & Mia eStudios
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
RAKESH SAJJAN
 

Built-in Functions in SQL | Numeric Functions

  • 1. Built-in Functions in SQL Numeric Functions Function Input Argument Value Returned ABS ( m ) m = value Absolute value of m MOD ( m, n ) m = value, n = divisor Remainder of m divided by n POWER ( m, n ) m = value, n = exponent m raised to the nth power ROUND ( m [, n ] ) m = value, n = number of decimal places, default 0 m rounded to the nth decimal place TRUNC ( m [, n ] ) m = value, n = number of decimal places, default 0 m truncated to the nth decimal place SIN ( n ) n = angle expressed in radians sine (n) COS ( n ) n = angle expressed in radians cosine (n) TAN ( n ) n = angle expressed in radians tan (n) SQRT ( n ) n = value positive square root of n EXP ( n ) n = value e raised to the power n LN ( n ) n > 0 natural logarithm of n LOG ( n2, n1 ) base n2 any positive value other than 0 or 1, n1 any positive value logarithm of n1, base n2 CEIL ( n ) n = value smallest integer greater than or equal to n FLOOR ( n ) n = value greatest integer smaller than or equal to n SIGN ( n ) n = value -1 if n < 0, 0 if n = 0, and 1 if n > 0 SQL Server allows DUAL to be specified as a table in queries that do not need data from any tables. Here are some examples of the use of some of these numeric functions: select round (83.28749,2) from dual; or simply write select round (83.28749,2); select sqrt (3.67) from dual; select power (2.512,5) from dual; String Functions Function Input Argument Value Returned INITCAP ( s ) s = character string First letter of each word is changed to uppercase and all other letters are in lower case. LOWER ( s ) s = character string All letters are changed to lowercase. UPPER ( s ) s = character string All letters are changed to uppercase.
  • 2. CONCAT ( s1, s2 ) s1 and s2 are character strings Concatenation of s1 and s2. Equivalent to s1 || s2 LPAD ( s1, n [, s2] ) s1 and s2 are character strings and n is an integer value Returns s1 right justified and padded left with n characters from s2; s2 defaults to space. RPAD ( s1, n [, s2] ) s1 and s2 are character strings and n is an integer value Returns s1 left justified and padded right with n characters from s2; s2 defaults to space. LTRIM ( s [, set ] ) s is a character string and set is a set of characters Returns s with characters removed up to the first character not in set; defaults to space RTRIM ( s [, set ] ) s is a character string and set is a set of characters Returns s with final characters removed after the last character not in set; defaults to space REPLACE ( s, search_s [, replace_s ] ) s = character string, search_s = target string, replace_s = replacement string Returns s with every occurrence of search_s in s replaced by replace_s; default removes search_s SUBSTR ( s, m [, n ] ) s = character string, m = beginning position, n = number of characters Returns a substring from s, beginning in position m and n characters long; default returns to end of s. LENGTH ( s ) s = character string Returns the number of characters in s. INSTR ( s1, s2 [, m [, n ] ] ) s1 and s2 are character strings, m = beginning position, n = occurrence of s2 in s1 Returns the position of the nth occurrence of s2 in s1, beginning at position m, both m and n default to 1. Here are some examples of the use of String functions: select concat ('Alan', 'Turing') as "NAME" from dual; select 'Alan' || 'Turing' as "NAME" from dual; select initcap ("now is the time for all good men to come to the aid of the party") as "SLOGAN" from dual; select substr('Alan Turing', 1, 4) as "FIRST" from dual; String / Number Conversion Functions Function Input Argument Value Returned TO_CHAR ( m [, fmt ] ) m = numeric value, fmt = format Number m converted to character string as specified by the format TO_NUMBER ( s [, fmt ] ) s = character string, fmt = format Character string s converted to a number as specified by the format
  • 3. Formats for TO_CHAR Function Symbol Explanation 9 Each 9 represents one digit in the result 0 Represents a leading zero to be displayed $ Floating dollar sign printed to the left of number L Any local floating currency symbol . Prints the decimal point , Prints the comma to represent thousands Group Functions Function Input Argument Value Returned AVG ( [ DISTINCT | ALL ] col ) col = column name The average value of that column COUNT ( * ) none Number of rows returned including duplicates and NULLs COUNT ( [ DISTINCT | ALL ] col ) col = column name Number of rows where the value of the column is not NULL MAX ( [ DISTINCT | ALL ] col ) col = column name Maximum value in the column MIN ( [ DISTINCT | ALL ] col ) col = column name Minimum value in the column SUM ( [ DISTINCT | ALL ] col ) col = column name Sum of the values in the column Date and Time Functions Function Input Argument Value Returned ADD_MONTHS ( d, n ) d = date, n = number of months Date d plus n months LAST_DAY ( d ) d = date Date of the last day of the month containing d MONTHS_BETWEEN ( d, e ) d and e are dates Number of months by which e precedes d NEW_TIME ( d, a, b ) d = date, a = time zone (char), b = time zone (char) The date and time in time zone b when date d is for time zone a NEXT_DAY ( d, day ) d = date, day = day of the Date of the first day of the
  • 4. week week after d SYSDATE() none Current date and time GREATEST ( d1, d2, ..., dn ) d1 ... dn = list of dates Latest of the given dates LEAST ( d1, d2, ..., dn ) d1 ... dn = list of dates Earliest of the given dates Try: SELECT SYSDATE(); SELECT LAST_DAY(SYSDATE()); Date Formats Format Code Description Range of Values DD Day of the month 1 - 31 DY Name of the day in 3 uppercase letters SUN, ..., SAT DAY Complete name of the day in uppercase, padded to 9 characters SUNDAY, ..., SATURDAY MM Number of the month 1 - 12 MON Name of the month in 3 uppercase letters JAN, ..., DEC MONTH Name of the month in uppercase padded to a length of 9 characters JANUARY, ..., DECEMBER RM Roman numeral for the month I, ..., XII YY or YYYY Two or four digit year 71 or 1971 HH:MI:SS Hours : Minutes : Seconds 10:28:53 HH 12 or HH 24 Hour displayed in 12 or 24 hour format 1 - 12 or 1 - 24 MI Minutes of the hour 0 - 59 SS Seconds of the minute 0 - 59 AM or PM Meridian indicator AM or PM