SlideShare a Scribd company logo
SQL Fundamentals Oracle 11g
M U H A M M A D WA H E E D
O R AC L E DATA BA S E D E V E LO P E R
E M A I L : m .wa h e e d 3 6 6 8 @ g m a i l . co m
Lecture#6
SQL Functions
Function Structure
2
SQL Functions(cont’d)
Functions are powerful feature of SQL and can be used to do the
following:
•Perform calculations on data
•Modify individual data items
•Manipulate output for group of rows
•Format dates and numbers for display
•Convert column data type
3
SQL Functions(cont’d)
There are following two types of SQL functions:
•Single Row Functions
Operate on single rows only and return single result per row.
•Multiple Row Functions
Can be used to manipulate group of rows to generate single result
against group of rows and also known as “Group Functions”.
*For now, We will consider only single-row functions.
4
Single-Row Functions
There are following types of single-row functions:
5
Single-Row(cont’d)
There are following types of character function:
6
Character Functions
There are following case-manipulation functions:
•LOWER(<column_name>|<expression>)
converts alpha characters to lowercase
•UPPER(<column_name>|<expression>)
converts alpha characters to uppercase
•INITCAP(<column_name>|<expression>)
capitalize the first letter of each word
7
Character Functions(cont’d)
•CONCAT(<column_name1>|<expression1>,
(<column_name2>|<expression2>))
equivalent to concatination operator
•SUBSTR(<column_name>|<expression>,M[,N])
returns characters starting from m and ending at n. As n is optional
if it is skipped then by default characters are returned from m to end
of characters.
•LENGTH(<column_name>|<expression>)
returns total no. of characters
8
Character Functions(cont’d)
9
Character Functions(cont’d)
10
Use of Character Functions
11
•Example:
SELECT std_id, CONCAT(std_first_name,std_last_name) AS
std_name, LENGTH(std_address), INSTR( std_address, ‘#’)
FROM student
WHERE SUBSTR(std_name,2,3) = ‘ai’;
Number Functions
12
•Number functions input as well as output only numeric values.
Number Functions(cont’d)
13
•Number functions input as well as output only numeric values.
Number Functions(cont’d)
14
•It can have negative value of ‘n’.
•Example:
SELECT ROUND(45.926,-1) FROM DUAL;
Result: 50
SELECT TRUNC(45.926,-2) FROM DUAL;
Result: 0
Date Functions
15
•For current date we use:
SELECT SYSDATE FROM DUAL;
Result( standard/default format): 26-APR-18
Elements of Date Functions
16
Date Functions(cont’d)
17
Arithmetic - Date Functions(cont’d)
18
Use Date Functions(cont’d)
19
•Example:
SELECT std_id, (SYSDATE - admission_date)/ 7 AS weeks
FROM student;
Use Date Functions(cont’d)
20
Implicit type casting
21
•For assignments, Oracle server can automatically convert following:
Implicit type casting(cont’d)
22
•For expression, Oracle server can automatically convert following:
Explicit type casting
23
Explicit type casting(cont’d)
24
Type casting - Date Functions(cont’d)
25
•Example:
i- SELECT std_id, TO_CHAR(admission_date,’MM/YY’)
FROM student;
ii- SELECT std_id, TO_CHAR(admission_date,’Day Month DD,YYYY’)
AS “Admission Date”
FROM student;
iii- SELECT std_id, TO_CHAR(admission_date,’fmDay Month DD,YYYY’)
AS “Admission Date”
FROM student;
Type casting - Date Functions(cont’d)
26
•Example:
i- SELECT std_id, TO_DATE(’27-APR-2018,’MM/YY’)
FROM student;
ii- SELECT std_id, TO_DATE(‘MAY 27,2018’,’fxMonth DD,YYYY’) AS
“Admission Date”
FROM student;
Type casting - Date Functions(cont’d)
27
•Example:
SELECT std_id, TO_CHAR(admission_date,’ fmDD MONTH,YYYY
fmHH12:MI:SS AM’)
FROM student;
•Result(TO_CHAR): 26 APRIL,2018 2:00:00 PM
Motivational Speaking
28
NVL Function
29
•Converts a null value to an actual value
•Syntax:
NVL(<column/experession>,<value>)
•Used with NUMBER,VARCHAR2 and DATE datatypes
•Data types must match for actual value
- NVL(std_age,0)
- NVL(std_address,’Pakistan’)
- NVL(std_dob,’01-JAN-00’)
CASE Function
30
•It provides IF-THEN-ELSE nesting facility in SQL
•Syntax:
CASE Function(cont’d)
31
•Example:
SELECT tch_id,tch_name,tch_salary,
CASE tch_designation WHEN ‘VISITING’ salary*1.1
WHEN ‘ASSISTANT LECTURER’ salary*1.2
WHEN ‘LECTURER’ salary*1.5
ELSE salary END AS “Revised Salary”
FROM teacher;
•*Note: same functionality can be performed using DECODE in
Oracle. Do it by yourself.
Records Manipulation Function
32
•There are few such functions: COUNT,MAX,MIN
•Example:
i- SELECT COUNT(*) FROM student;
ii- SELECT MAX(tch_salary) FROM teacher;
iii- SELECT MIN(std_dob) FROM student;
Nested Single-row Functions
33
•Single functions can be nested to any level.
Nested Single-row Functions
34
•Single functions can be nested to any level.
SELECT NVL(TO_CHAR(std_dob,’MON DD,YYYY’),’NO VALUE’)
FROM student;
Feedback/Suggestions?
The feedback I get is that my books are honest.
- Laurie Halse Anderson

More Related Content

What's hot (20)

PDF
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...
Rishikesh Agrawani
 
PDF
SQL Fundamentals - Lecture 2
MuhammadWaheed44
 
PPT
Session 6
Shailendra Mathur
 
PPTX
Oracle: Basic SQL
DataminingTools Inc
 
PPTX
Java Tutorial Lab 8
Berk Soysal
 
PDF
Refinement Types for Haskell
Martin Ockajak
 
PDF
Introduction to oracle functions
Nitesh Singh
 
PDF
Comparing Haskell & Scala
Martin Ockajak
 
PPTX
Oracle: Functions
DataminingTools Inc
 
PDF
JavaScript: Variables and Functions
Jussi Pohjolainen
 
PPT
358 33 powerpoint-slides_6-strings_chapter-6
sumitbardhan
 
PPTX
Sql operator
Pooja Dixit
 
PDF
Scala for Java Developers
Martin Ockajak
 
PPTX
Queues
nidhisatija1
 
PDF
Introduction To Oracle Sql
Ahmed Yaseen
 
PPTX
Java Tutorial Lab 7
Berk Soysal
 
PPTX
Java Tutorial Lab 5
Berk Soysal
 
PPTX
MYSQL single rowfunc-multirowfunc-groupby-having
Ahmed Farag
 
PPTX
MYSql manage db
Ahmed Farag
 
PDF
SQL Functions and Operators
Mohan Kumar.R
 
C++ Templates_ Program to Swap Two Numbers Using Function Template - The Craz...
Rishikesh Agrawani
 
SQL Fundamentals - Lecture 2
MuhammadWaheed44
 
Oracle: Basic SQL
DataminingTools Inc
 
Java Tutorial Lab 8
Berk Soysal
 
Refinement Types for Haskell
Martin Ockajak
 
Introduction to oracle functions
Nitesh Singh
 
Comparing Haskell & Scala
Martin Ockajak
 
Oracle: Functions
DataminingTools Inc
 
JavaScript: Variables and Functions
Jussi Pohjolainen
 
358 33 powerpoint-slides_6-strings_chapter-6
sumitbardhan
 
Sql operator
Pooja Dixit
 
Scala for Java Developers
Martin Ockajak
 
Queues
nidhisatija1
 
Introduction To Oracle Sql
Ahmed Yaseen
 
Java Tutorial Lab 7
Berk Soysal
 
Java Tutorial Lab 5
Berk Soysal
 
MYSQL single rowfunc-multirowfunc-groupby-having
Ahmed Farag
 
MYSql manage db
Ahmed Farag
 
SQL Functions and Operators
Mohan Kumar.R
 

Similar to SQL Functions - Oracle SQL Fundamentals (20)

PPTX
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
DrkhanchanaR
 
PPT
Single-Row Functions in orcale Data base
Salman Memon
 
PDF
lab2sql222222222222222222222222222222222
227567
 
PDF
SQL BUILT-IN FUNCTION
Arun Sial
 
PPT
Les03
arnold 7490
 
PDF
Oracle sql functions
Vivek Singh
 
PPT
Single row functions
Balqees Al.Mubarak
 
PPT
Les03 Single Row Functions in Oracle and SQL.ppt
DrZeeshanBhatti
 
PPT
Built in functions singlerow & group.ppt
sivamathi12
 
PPT
Les03
Vijay Kumar
 
PPTX
Les03.pptx
NishaTariq1
 
PPTX
Function and types
Sherin Fathima
 
PPT
Les03[1] Single-Row Functions
siavosh kaviani
 
PPT
Using single row functions to customize output
Syed Zaid Irshad
 
PDF
Sql functions
Ankit Dubey
 
PPT
Single row functions
Soumyajit Dutta
 
PPT
Les03 (Using Single Row Functions To Customize Output)
Achmad Solichin
 
PPT
Oracle sql ppt2
Madhavendra Dutt
 
PPT
Les03
Sudharsan S
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
DrkhanchanaR
 
Single-Row Functions in orcale Data base
Salman Memon
 
lab2sql222222222222222222222222222222222
227567
 
SQL BUILT-IN FUNCTION
Arun Sial
 
Oracle sql functions
Vivek Singh
 
Single row functions
Balqees Al.Mubarak
 
Les03 Single Row Functions in Oracle and SQL.ppt
DrZeeshanBhatti
 
Built in functions singlerow & group.ppt
sivamathi12
 
Les03.pptx
NishaTariq1
 
Function and types
Sherin Fathima
 
Les03[1] Single-Row Functions
siavosh kaviani
 
Using single row functions to customize output
Syed Zaid Irshad
 
Sql functions
Ankit Dubey
 
Single row functions
Soumyajit Dutta
 
Les03 (Using Single Row Functions To Customize Output)
Achmad Solichin
 
Oracle sql ppt2
Madhavendra Dutt
 
Ad

Recently uploaded (20)

DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PDF
Next level data operations using Power Automate magic
Andries den Haan
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
Next level data operations using Power Automate magic
Andries den Haan
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Ad

SQL Functions - Oracle SQL Fundamentals