Professional Documents
Culture Documents
OBJECTIVES
After completing this lesson, you should be able
to do the following:
1.Describes various types of functions available in
SQL.
2.Use character, number, and date functions in
SELECT statements.
3.Describe the use of conversion functions.
SQL FUNCTIONS
Functions are a very powerful feature of SQL
and can be used to do the following:
1.Perform calculations on data
2.Modify individual data items
3.Manipulate output for groups of rows
4.Formats dates and numbers for display
5.Convert column data types
CHARACTER FUNCTIONS
Case
manipulation
Character
manipulation
LOWER
CONCAT
UPPER
SUBSTR
INITCAP
LENGTH
INSTR
LPAD/RPAD
TRIM
Result
sql course
SQL
COURSE
CHARACTER MANIPULATION
FUNTIONS
Function
Result
CONCAT(Hello, World)
HelloWorld
SUBSTR(HelloWorld, 1,5)
Hello
LENGTH (HelloWorld)
10
INSTR(HelloWorld,W)
LPAD(salary,10,*)
*****24000
RPAD(salary,10,*)
24000*****
10 rows selected
Name
100kingsteven
101kocharnena
102de haanlex
103hunoldalexander
104ernstbruce
107Lorentzdiana
104ernstbruce
lorentzdian
6
5
0
0
Name
mourgoske
124 vin
job_id
length(last_nam instr(last_name,
e)
'a')
st_clerk
7
141rajstrina st_clerk
4
daviascu
Note: SUBSTR search for the employees who have the string
rtis in the job_id
st_clerk
6
clerck142
contained
stating at fourth position.
0
2
2
it_prog
ernstbruce it_prog
lorentzdian
a
st_man
lpad(salary,4,' rpad(salary,2,'$
@')
')
2400
1700
1700
24
17
17
9000
6000
90
60
4200
42
NUMBER FUNCTIONS
ROUND: rounds value to specified decimal
ROUND (45.926, 2) = 45.93
NUMBER FUNCTIONS
Number functions accept numeric input and
return numeric value.
Function
Purpose
Round (column |
expression, n)
trunc (column |
expression, n)
Mod(m,n)
FROM
ROUND(45.923,2),ROUND(45.923,0),
ROUND(45.923, -1), ROUND(45.923)
DUAL;
45.92
46
50
46
round(salary),round(salary),
round(salary,-1)
employees
job_id = 'st_clerk';
round(salary)
round(salary)
round(salary,-1)
58000
58000
58000
58000
58000
58000
58000
58000
58000
TRUNCATE(45.923,2),
TRUNCATE(45.923,0),
TRUNCATE(45.923,-1)
DUAL;
45.92
45
40
MOD(1600,300)
DUAL;
MOD(1600,300)
100