A practical approach towards learning SQL in Oracle 11g. Video lectures are prepared as well and can be found at given link
https://www.youtube.com/channel/UCMv6HrS_4_GFWmLLFzL_U_A?view_as=subscriber
1 of 35
Downloaded 52 times
More Related Content
SQL Functions - Oracle SQL Fundamentals
1. 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
3. SQL Functions(contd)
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
4. SQL Functions(contd)
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
7. 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
11. 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;
14. Number Functions(contd)
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
25. Type casting - Date Functions(contd)
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;
26. Type casting - Date Functions(contd)
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;
27. Type casting - Date Functions(contd)
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
29. 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)
31. CASE Function(contd)
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.
32. 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;