- •Objectivesj i
- •Usingi the Character
- •SQL Functionsi
- •Two Types of SQL Functionsi
- •Singlei le-Row Functionsi
- •Singlei le-Row Functionsi
- •Character Functionsi
- •Case Conversioni Functionsi
- •Usingi Case Conversioni Functionsi
- •Character Manipulationi l i Functionsi
- •Number Functionsi
- •Usingi the ROUND Functioni
- •Usingi the TRUNC Functioni
- •Usingi the MOD Functioni
- •Workingi withi Dates
- •Arithmetici ic withi Dates
- •Usingi Arithmetici ic Operators withi Dates
- •Date Functionsi
- •Usingi Date Functionsi
- •Usingi Date Functionsi
- •Conversioni Functionsi
- •ImplicitI li it Datatype Conversioni
- •ImplicitI li it Datatype Conversioni
- •Explicitli it Datatype Conversioni
- •TO_CHAR Functioni withi Dates
- •Date Format Modell Elementsl
- •Date Format Modell Elementsl
- •Usingi TO_CHAR Functioni
- •TO_CHAR Functioni withi Numbers
- •Usingi TO_CHAR Functioni
- •TO_NUMBER and TO_DATE Functionsi
- •RR Date Format
- •NVL Functioni
- •Usingi the NVL Functioni
- •DECODE Functioni
- •Usingi the DECODE Functioni
- •Nestingi Functionsi
- •Nestingi Functionsi
- •Summary
- •Practicei Overviewi
Number Functionsi
•• ROUND:: Rounds valuel toto specifiedifi decimali l
ROUND(45( ..926,, 2)) 45..93
•• TRUNC::Truncatesr t valuel toto specifiedifi decimali l
TRUNC(45( ..926,, 2)) 45..92
•• MOD:: Returnst r remainderr i r off divisioni i i
MOD(1600,( , 300)) 100

3-12
Usingi the ROUND Functioni
SQL> SELECT ROUND(45.923,2), ROUND(45.923,0), 2 ROUND(45.923,-1)
3 FROM DUAL;
ROUND(45.923,2) ROUND(45.923,0) ROUND(45.923,-1)
--------------- |
-------------- |
----------------- |
45.92 |
46 |
50 |
3-13
Usingi the TRUNC Functioni
SQL> SELECT TRUNC(45.923,2), TRUNC(45.923), 2 TRUNC(45.923,-1)
3 FROM DUAL;
|
|
|
|
|
|
TRUNC(45.923,2) TRUNC(45.923) |
TRUNC(45.923,-1) |
|
|
|
--------------- |
------------- |
--------------- |
|
|
45.92 |
45 |
40 |
|
|
|
|
|
|
3-14
Usingi the MOD Functioni
Calculate the remainder of the ratio of salary to commission for all employees whose job title is a salesman.
|
|
|
|
|
|
SQL> |
SELECT |
ename, sal, comm, MOD(sal, comm) |
|
|
2 |
FROM |
emp |
|
|
3 |
WHERE |
job = 'SALESMAN'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ENAME |
SAL |
COMM MOD(SAL,COMM) |
|
|
|
---------- |
|
--------- --------- ------------- |
|
||
|
|
MARTIN |
1250 |
1400 |
1250 |
|
|
|
ALLEN |
1600 |
300 |
100 |
|
|
|
TURNER |
1500 |
0 |
1500 |
|
|
|
WARD |
1250 |
500 |
250 |
|
|
|
|
|
|
|
|
3-15
Workingi withi Dates
•• Oracler le storest r datest inin an internali t r l numericric formatf r t:: Century,t r , year,r, month,t , day,, hours,r , minutes,i t , seconds..
•• The defaultf lt datete formatf r t isis DD--MON--YY..
•• SYSDATE isis a functionf ti returningr t r i datete and timeti ..
•• DUAL isis a dummy tablet le used toto viewi
SYSDATE..
3-16
Arithmetici ic withi Dates
•• Add orr subtracttr t a numberr toto orr fromfr a datete forf r a resultantr lt t datete valuel ..
•• Subtracttr t twot datest toto findfi thet numberr off days betweent thoset datest ..
•• Add hoursrs toto a datete by dividingi i i thet numberr off hoursrs by 24..
3-17
Usingi Arithmetici ic Operators withi Dates
SQL> SELECT ename, (SYSDATE-hiredate)/7 WEEKS 2 FROM emp
3WHERE deptno = 10;
|
|
|
|
|
ENAME |
WEEKS |
|
|
---------- |
--------- |
|
|
KING |
830.93709 |
|
|
CLARK |
853.93709 |
|
|
MILLER |
821.36566 |
|
|
|
|
|
3-18
Date Functionsi
FUNCTION |
DESCRIPTION |
|
|
|
|
|
|
|
MONTHS_BETWEEN |
Number of months |
|
between two dates |
||
|
||
ADD_MONTHS |
Add calendar months to |
|
date |
||
|
||
NEXT_DAY |
Next day of the date |
|
specified |
||
|
||
LAST_DAY |
Last day of the month |
|
ROUND |
Round date |
|
|
||
|
|
|
TRUNC |
Truncate date |
|
|
||
|
|
3-19
Usingi Date Functionsi
• MONTHS_BETWEEN ('01-SEP-95','11-JAN-94')
19.6774194
• ADD_MONTHS ('11-JAN-94',6) |
|
|
|
'11-JUL-94' |
|
|
|
• NEXT_DAY ('01-SEP-95','FRIDAY') 
'08-SEP-95'
• LAST_DAY('01-SEP-95') |
|
|
|
'30-SEP-95' |
|
|
|
3-20
Usingi Date Functionsi
• ROUND('25-JUL-95','MONTH') 
01-AUG-95
• ROUND('25-JUL-95','YEAR') |
|
|
|
01-JAN-96 |
|
|
|
• TRUNC('25-JUL-95','MONTH') 
01-JUL-95
• TRUNC('25-JUL-95','YEAR') |
|
|
|
01-JAN-95 |
|
|
|
3-21
