SlideShare a Scribd company logo
3
Copyright © Oracle Corporation, 2001. All rights reserved.
Single-Row Functions
3-2 Copyright © Oracle Corporation, 2001. All rights reserved.
Objectives
After completing this lesson, you should be able to
do the following:
• Describe various types of functions available
in SQL
• Use character, number, and date functions in
SELECT statements
• Describe the use of conversion functions
3-3 Copyright © Oracle Corporation, 2001. All rights reserved.
SQL Functions
FunctionFunction
Input
arg 1arg 1
arg 2arg 2
argarg nn
Function
performs action
Output
ResultResult
valuevalue
3-4 Copyright © Oracle Corporation, 2001. All rights reserved.
Two Types of SQL Functions
FunctionsFunctions
Single-rowSingle-row
functionsfunctions
Multiple-rowMultiple-row
functionsfunctions
3-5 Copyright © Oracle Corporation, 2001. All rights reserved.
Single-Row Functions
Single row functions:
• Manipulate data items
• Accept arguments and return one value
• Act on each row returned
• Return one result per row
• May modify the data type
• Can be nested
• Accept arguments which can be a column or an
expression
function_name [(arg1, arg2,...)]function_name [(arg1, arg2,...)]
3-6 Copyright © Oracle Corporation, 2001. All rights reserved.
Single-Row Functions
ConversionConversion
CharacterCharacter
NumberNumber
DateDate
GeneralGeneral
Single-rowSingle-row
functionsfunctions
3-7 Copyright © Oracle Corporation, 2001. All rights reserved.
Character Functions
CharacterCharacter
functionsfunctions
LOWER
UPPER
INITCAP
CONCAT
SUBSTR
LENGTH
INSTR
LPAD | RPAD
TRIM
REPLACE
Case-manipulationCase-manipulation
functionsfunctions
Character-manipulationCharacter-manipulation
functionsfunctions
3-9 Copyright © Oracle Corporation, 2001. All rights reserved.
Function Result
Case Manipulation Functions
These functions convert case for character strings.
LOWER('SQL Course')
UPPER('SQL Course')
INITCAP('SQL Course')
sql course
SQL COURSE
Sql Course
3-10 Copyright © Oracle Corporation, 2001. All rights reserved.
Using Case Manipulation Functions
Display the employee number, name, and department
number for employee Higgins:
SELECT employee_id, last_name, department_id
FROM employees
WHERE last_name = 'higgins';
no rows selectedno rows selected
SELECT employee_id, last_name, department_id
FROM employees
WHERE last_name = 'higgins';
no rows selectedno rows selected
SELECT employee_id, last_name, department_id
FROM employees
WHERE LOWER(last_name) = 'higgins';
3-11 Copyright © Oracle Corporation, 2001. All rights reserved.
CONCAT('Hello', 'World')
SUBSTR('HelloWorld',1,5)
LENGTH('HelloWorld')
INSTR('HelloWorld', 'W')
LPAD(salary,10,'*')
RPAD(salary, 10, '*')
TRIM('H' FROM 'HelloWorld')
HelloWorld
Hello
10
6
*****24000
24000*****
elloWorld
Function Result
Character-Manipulation Functions
These functions manipulate character strings:
3-12 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT employee_id, CONCAT(first_name, last_name) NAME,
job_id, LENGTH (last_name),
INSTR(last_name, 'a') "Contains 'a'?"
FROM employees
WHERE SUBSTR(job_id, 4) = 'REP';
Using the Character-Manipulation
Functions
1
2
31 2
3
3-13 Copyright © Oracle Corporation, 2001. All rights reserved.
Number Functions
• ROUND: Rounds value to specified decimal
ROUND(45.926, 2) 45.93
• TRUNC: Truncates value to specified decimal
TRUNC(45.926, 2) 45.92
• MOD: Returns remainder of division
MOD(1600, 300) 100
3-14 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT ROUND(45.923,2), ROUND(45.923,0),
ROUND(45.923,-1)
FROM DUAL;
Using the ROUND Function
DUAL is a dummy table you can use to view results
from functions and calculations.
1 2
3
31 2
3-15 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT TRUNC(45.923,2), TRUNC(45.923),
TRUNC(45.923,-2)
FROM DUAL;
Using the TRUNC Function
31 2
1 2
3
3-16 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT last_name, salary, MOD(salary, 5000)
FROM employees
WHERE job_id = 'SA_REP';
Using the MOD Function
Calculate the remainder of a salary after it is divided
by 5000 for all employees whose job title is sales
representative.
3-17 Copyright © Oracle Corporation, 2001. All rights reserved.
Working with Dates
• Oracle database stores dates in an internal
numeric format: century, year, month, day, hours,
minutes, seconds.
• The default date display format is DD-MON-RR.
– Allows you to store 21st century dates in the 20th
century by specifying only the last two digits of the
year.
– Allows you to store 20th century dates in the 21st
century in the same way.
SELECT last_name, hire_date
FROM employees
WHERE last_name like ''G%';';
3-18 Copyright © Oracle Corporation, 2001. All rights reserved.
Working with Dates
SYSDATE is a function that returns:
• Date
• Time
3-19 Copyright © Oracle Corporation, 2001. All rights reserved.
Arithmetic with Dates
• Add or subtract a number to or from a date for a
resultant date value.
• Subtract two dates to find the number of days
between those dates.
• Add hours to a date by dividing the number of
hours by 24.
3-20 Copyright © Oracle Corporation, 2001. All rights reserved.
Using Arithmetic Operators
with Dates
SELECT last_name, (SYSDATE-hire_date)/7 AS WEEKS
FROM employees
WHERE department_id = 90;
3-21 Copyright © Oracle Corporation, 2001. All rights reserved.
Date Functions
Number of months
between two dates
MONTHS_BETWEEN
ADD_MONTHS
NEXT_DAY
LAST_DAY
ROUND
TRUNC
Add calendar months to
date
Next day of the date
specified
Last day of the month
Round date
Truncate date
Function Description
3-22 Copyright © Oracle Corporation, 2001. All rights reserved.
• MONTHS_BETWEEN ('01-SEP-95','11-JAN-94')
Using Date Functions
• ADD_MONTHS ('11-JAN-94',6)
• NEXT_DAY ('01-SEP-95','FRIDAY')
• LAST_DAY('01-FEB-95')
19.6774194
'11-JUL-94'
'08-SEP-95'
'28-FEB-95'
3-23 Copyright © Oracle Corporation, 2001. All rights reserved.
• ROUND(SYSDATE,'MONTH') 01-AUG-95
• ROUND(SYSDATE ,'YEAR') 01-JAN-96
• TRUNC(SYSDATE ,'MONTH') 01-JUL-95
• TRUNC(SYSDATE ,'YEAR') 01-JAN-95
Using Date Functions
Assume SYSDATE = '25-JUL-95':
3-24 Copyright © Oracle Corporation, 2001. All rights reserved.
Practice 3, Part One: Overview
This practice covers the following topics:
• Writing a query that displays the current date
• Creating queries that require the use of numeric,
character, and date functions
• Performing calculations of years and months of
service for an employee
3-25 Copyright © Oracle Corporation, 2001. All rights reserved.
Conversion Functions
Implicit data typeImplicit data type
conversionconversion
Explicit data typeExplicit data type
conversionconversion
Data typeData type
conversionconversion
3-26 Copyright © Oracle Corporation, 2001. All rights reserved.
Implicit Data Type Conversion
For assignments, the Oracle server can automatically
convert the following:
VARCHAR2 or CHAR
From To
VARCHAR2 or CHAR
NUMBER
DATE
NUMBER
DATE
VARCHAR2
VARCHAR2
3-27 Copyright © Oracle Corporation, 2001. All rights reserved.
Implicit Data Type Conversion
For expression evaluation, the Oracle Server can
automatically convert the following:
VARCHAR2 or CHAR
From To
VARCHAR2 or CHAR
NUMBER
DATE
3-28 Copyright © Oracle Corporation, 2001. All rights reserved.
Explicit Data Type Conversion
NUMBER CHARACTER
TO_CHAR
TO_NUMBER
DATE
TO_CHAR
TO_DATE
3-29 Copyright © Oracle Corporation, 2001. All rights reserved.
Explicit Data Type Conversion
NUMBER CHARACTER
TO_CHAR
TO_NUMBER
DATE
TO_CHAR
TO_DATE
3-31 Copyright © Oracle Corporation, 2001. All rights reserved.
Using the TO_CHAR Function with Dates
The format model:
• Must be enclosed in single quotation marks and is case
sensitive
• Can include any valid date format element
• Has an fm element to remove padded blanks or
suppress leading zeros
• Is separated from the date value by a comma
TO_CHAR(date, 'format_model')TO_CHAR(date, 'format_model')
3-32 Copyright © Oracle Corporation, 2001. All rights reserved.
YYYY
Elements of the Date Format Model
YEAR
MM
MONTH
DY
DAY
Full year in numbers
Year spelled out
Two-digit value for month
Three-letter abbreviation of the
day of the week
Full name of the day of the week
Full name of the month
MON
Three-letter abbreviation of the
month
DD Numeric day of the month
3-34 Copyright © Oracle Corporation, 2001. All rights reserved.
Elements of the Date Format Model
• Time elements format the time portion of the date.
• Add character strings by enclosing them in double
quotation marks.
• Number suffixes spell out numbers.
HH24:MI:SS AM 15:45:32 PM
DD "of" MONTH 12 of OCTOBER
ddspth fourteenth
3-36 Copyright © Oracle Corporation, 2001. All rights reserved.
Using the TO_CHAR Function with Dates
SELECT last_name,
TO_CHAR(hire_date, 'fmDD Month YYYY')
AS HIREDATE
FROM employees;
…
3-37 Copyright © Oracle Corporation, 2001. All rights reserved.
Using the TO_CHAR Function with
Numbers
These are some of the format elements you can use
with the TO_CHAR function to display a number value
as a character:
TO_CHAR(number, 'format_model')TO_CHAR(number, 'format_model')
9
0
$
L
.
,
Represents a number
Forces a zero to be displayed
Places a floating dollar sign
Uses the floating local currency symbol
Prints a decimal point
Prints a thousand indicator
3-38 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT TO_CHAR(salary, '$99,999.00') SALARY
FROM employees
WHERE last_name = 'Ernst';
Using the TO_CHAR Function with Numbers
3-39 Copyright © Oracle Corporation, 2001. All rights reserved.
Using the TO_NUMBER and TO_DATE
Functions
• Convert a character string to a number format
using the TO_NUMBER function:
• Convert a character string to a date format using
the TO_DATE function:
• These functions have an fx modifier. This modifier
specifies the exact matching for the character
argument and date format model of a TO_DATE
function
TO_NUMBER(char[, 'format_model'])TO_NUMBER(char[, 'format_model'])
TO_DATE(char[, 'format_model'])TO_DATE(char[, 'format_model'])
3-40 Copyright © Oracle Corporation, 2001. All rights reserved.
Using the TO_NUMBER and TO_DATE
Functions
• Convert a character string to a number format
using the TO_NUMBER function:
• Convert a character string to a date format using
the TO_DATE function:
• These functions have an fx modifier. This modifier
specifies the exact matching for the character
argument and date format model of a TO_DATE
function
TO_NUMBER(char[, 'format_model'])TO_NUMBER(char[, 'format_model'])
TO_DATE(char[, 'format_model'])TO_DATE(char[, 'format_model'])
3-41 Copyright © Oracle Corporation, 2001. All rights reserved.
RR Date Format
Current Year
1995
1995
2001
2001
Specified Date
27-OCT-95
27-OCT-17
27-OCT-17
27-OCT-95
RR Format
1995
2017
2017
1995
YY Format
1995
1917
2017
2095
If two digits
of the
current
year are:
0–49
0–49 50–99
50–99
The return date is in
the current century
The return date is
in the century after
the current one
The return date is in
the century before
the current one
The return date is in
the current century
If the specified two-digit year is:
3-42 Copyright © Oracle Corporation, 2001. All rights reserved.
Example of RR Date Format
To find employees hired prior to 1990, use the RR
format, which produces the same results whether the
command is run in 1999 or now:
SELECT last_name, TO_CHAR(hire_date, 'DD-Mon-YYYY')
FROM employees
WHERE hire_date < TO_DATE('01-Jan-90', 'DD-Mon-RR');
3-43 Copyright © Oracle Corporation, 2001. All rights reserved.
Nesting Functions
• Single-row functions can be nested to any level.
• Nested functions are evaluated from deepest level
to the least deep level.
F3(F2(F1(col,arg1),arg2),arg3)
Step 1 = Result 1
Step 2 = Result 2
Step 3 = Result 3
3-44 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT last_name,
NVL(TO_CHAR(manager_id), 'No Manager')
FROM employees
WHERE manager_id IS NULL;
Nesting Functions
3-45 Copyright © Oracle Corporation, 2001. All rights reserved.
General Functions
These functions work with any data type and pertain
to using nulls.
• NVL (expr1, expr2)
• NVL2 (expr1, expr2, expr3)
• NULLIF (expr1, expr2)
• COALESCE (expr1, expr2, ..., exprn)
3-46 Copyright © Oracle Corporation, 2001. All rights reserved.
NVL Function
Converts a null to an actual value.
• Data types that can be used are date, character,
and number.
• Data types must match:
– NVL(commission_pct,0)
– NVL(hire_date,'01-JAN-97')
– NVL(job_id,'No Job Yet')
3-47 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT last_name, salary, NVL(commission_pct, 0),
(salary*12) + (salary*12*NVL(commission_pct, 0)) AN_SAL
FROM employees;
Using the NVL Function
…
1 2
1
2
3-48 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT last_name, salary, commission_pct,
NVL2(commission_pct,
'SAL+COMM', 'SAL') income
FROM employees WHERE department_id IN (50, 80);
Using the NVL2 Function
1 2
1
2
3-49 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT first_name, LENGTH(first_name) "expr1",
last_name, LENGTH(last_name) "expr2",
NULLIF(LENGTH(first_name), LENGTH(last_name)) result
FROM employees;
Using the NULLIF Function
…
1
2
3
1 2 3
3-50 Copyright © Oracle Corporation, 2001. All rights reserved.
Using the COALESCE Function
• The advantage of the COALESCE function over the
NVL function is that the COALESCE function can
take multiple alternate values.
• If the first expression is not null, it returns that
expression; otherwise, it does a COALESCE of the
remaining expressions.
3-51 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT last_name,
COALESCE(commission_pct, salary, 10) comm
FROM employees
ORDER BY commission_pct;
Using the COALESCE Function
…
3-52 Copyright © Oracle Corporation, 2001. All rights reserved.
Conditional Expressions
• Provide the use of IF-THEN-ELSE logic within a
SQL statement
• Use two methods:
– CASE expression
– DECODE function
3-53 Copyright © Oracle Corporation, 2001. All rights reserved.
The CASE Expression
Facilitates conditional inquiries by doing the work of
an IF-THEN-ELSE statement:
CASE expr WHEN comparison_expr1 THEN return_expr1
[WHEN comparison_expr2 THEN return_expr2
WHEN comparison_exprn THEN return_exprn
ELSE else_expr]
END
CASE expr WHEN comparison_expr1 THEN return_expr1
[WHEN comparison_expr2 THEN return_expr2
WHEN comparison_exprn THEN return_exprn
ELSE else_expr]
END
3-54 Copyright © Oracle Corporation, 2001. All rights reserved.
SELECT last_name, job_id, salary,
CASE job_id WHEN 'IT_PROG' THEN 1.10*salary
WHEN 'ST_CLERK' THEN 1.15*salary
WHEN 'SA_REP' THEN 1.20*salary
ELSE salary END "REVISED_SALARY"
FROM employees;
Using the CASE Expression
Facilitates conditional inquiries by doing the work of
an IF-THEN-ELSE statement:
…
…
3-55 Copyright © Oracle Corporation, 2001. All rights reserved.
The DECODE Function
Facilitates conditional inquiries by doing the work of
a CASE or IF-THEN-ELSE statement:
DECODE(col|expression, search1, result1
[, search2, result2,...,]
[, default])
DECODE(col|expression, search1, result1
[, search2, result2,...,]
[, default])
3-56 Copyright © Oracle Corporation, 2001. All rights reserved.
Using the DECODE Function
SELECT last_name, job_id, salary,
DECODE(job_id, 'IT_PROG', 1.10*salary,
'ST_CLERK', 1.15*salary,
'SA_REP', 1.20*salary,
salary)
REVISED_SALARY
FROM employees;
…
…
3-57 Copyright © Oracle Corporation, 2001. All rights reserved.
Using the DECODE Function
SELECT last_name, salary,
DECODE (TRUNC(salary/2000, 0),
0, 0.00,
1, 0.09,
2, 0.20,
3, 0.30,
4, 0.40,
5, 0.42,
6, 0.44,
0.45) TAX_RATE
FROM employees
WHERE department_id = 80;
Display the applicable tax rate for each employee in
department 80.
3-58 Copyright © Oracle Corporation, 2001. All rights reserved.
Summary
In this lesson, you should have learned how to:
• Perform calculations on data using functions
• Modify individual data items using functions
• Manipulate output for groups of rows using
functions
• Alter date formats for display using functions
• Convert column data types using functions
• Use NVL functions
• Use IF-THEN-ELSE logic
3-59 Copyright © Oracle Corporation, 2001. All rights reserved.
Practice 3, Part Two: Overview
This practice covers the following topics:
• Creating queries that require the use of numeric,
character, and date functions
• Using concatenation with functions
• Writing case-insensitive queries to test the
usefulness of character functions
• Performing calculations of years and months of
service for an employee
• Determining the review date for an employee
3-60 Copyright © Oracle Corporation, 2001. All rights reserved.
3-62 Copyright © Oracle Corporation, 2001. All rights reserved.
Ad

More Related Content

What's hot (20)

Les01
Les01Les01
Les01
Abrianto Nugraha
 
Cursores.ppt
Cursores.pptCursores.ppt
Cursores.ppt
Alan737817
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
Achmad Solichin
 
02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
rehaniltifat
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata
rehaniltifat
 
Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base
Salman Memon
 
Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)
Achmad Solichin
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
Achmad Solichin
 
Restricting and sorting data
Restricting and sorting dataRestricting and sorting data
Restricting and sorting data
Syed Zaid Irshad
 
Oracle SQL - Aggregating Data Les 05.ppt
Oracle SQL - Aggregating Data Les 05.pptOracle SQL - Aggregating Data Les 05.ppt
Oracle SQL - Aggregating Data Les 05.ppt
DrZeeshanBhatti
 
4. plsql
4. plsql4. plsql
4. plsql
Amrit Kaur
 
Oraclesql
OraclesqlOraclesql
Oraclesql
Priya Goyal
 
Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
Achmad Solichin
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggers
rehaniltifat
 
Controlling User Access -Data base
Controlling User Access -Data baseControlling User Access -Data base
Controlling User Access -Data base
Salman Memon
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
Srinimf-Slides
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
Md Mudassir
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
Salman Memon
 
06 Using More Package Concepts
06 Using More Package Concepts06 Using More Package Concepts
06 Using More Package Concepts
rehaniltifat
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
Vikas Gupta
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
Achmad Solichin
 
02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
rehaniltifat
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata
rehaniltifat
 
Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base
Salman Memon
 
Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)Les05 (Displaying Data from Multiple Table)
Les05 (Displaying Data from Multiple Table)
Achmad Solichin
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
Achmad Solichin
 
Restricting and sorting data
Restricting and sorting dataRestricting and sorting data
Restricting and sorting data
Syed Zaid Irshad
 
Oracle SQL - Aggregating Data Les 05.ppt
Oracle SQL - Aggregating Data Les 05.pptOracle SQL - Aggregating Data Les 05.ppt
Oracle SQL - Aggregating Data Les 05.ppt
DrZeeshanBhatti
 
Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
Achmad Solichin
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggers
rehaniltifat
 
Controlling User Access -Data base
Controlling User Access -Data baseControlling User Access -Data base
Controlling User Access -Data base
Salman Memon
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
Srinimf-Slides
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
Md Mudassir
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
Salman Memon
 
06 Using More Package Concepts
06 Using More Package Concepts06 Using More Package Concepts
06 Using More Package Concepts
rehaniltifat
 

Viewers also liked (10)

Sample file processing
Sample file processingSample file processing
Sample file processing
Issay Meii
 
Oracle sql in 7 days by suesh.n v 1.0
Oracle sql in 7 days by suesh.n v 1.0Oracle sql in 7 days by suesh.n v 1.0
Oracle sql in 7 days by suesh.n v 1.0
nsureshreddy51
 
Sql task answers
Sql task answersSql task answers
Sql task answers
Nawaz Sk
 
File Processing System
File Processing SystemFile Processing System
File Processing System
DMMMSU-SLUC
 
Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorial
Mohd Tousif
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
Vikas Gupta
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...
Alex Zaballa
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
DataminingTools Inc
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERS
mohdoracle
 
The Top Skills That Can Get You Hired in 2017
The Top Skills That Can Get You Hired in 2017The Top Skills That Can Get You Hired in 2017
The Top Skills That Can Get You Hired in 2017
LinkedIn
 
Sample file processing
Sample file processingSample file processing
Sample file processing
Issay Meii
 
Oracle sql in 7 days by suesh.n v 1.0
Oracle sql in 7 days by suesh.n v 1.0Oracle sql in 7 days by suesh.n v 1.0
Oracle sql in 7 days by suesh.n v 1.0
nsureshreddy51
 
Sql task answers
Sql task answersSql task answers
Sql task answers
Nawaz Sk
 
File Processing System
File Processing SystemFile Processing System
File Processing System
DMMMSU-SLUC
 
Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorial
Mohd Tousif
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
Vikas Gupta
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...
Alex Zaballa
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERS
mohdoracle
 
The Top Skills That Can Get You Hired in 2017
The Top Skills That Can Get You Hired in 2017The Top Skills That Can Get You Hired in 2017
The Top Skills That Can Get You Hired in 2017
LinkedIn
 
Ad

Similar to Single-Row Functions in orcale Data base (20)

Les03 Single Row Functions in Oracle and SQL.ppt
Les03 Single Row Functions in Oracle and SQL.pptLes03 Single Row Functions in Oracle and SQL.ppt
Les03 Single Row Functions in Oracle and SQL.ppt
DrZeeshanBhatti
 
Built in functions singlerow & group.ppt
Built in functions singlerow & group.pptBuilt in functions singlerow & group.ppt
Built in functions singlerow & group.ppt
sivamathi12
 
Single row functions
Single row functionsSingle row functions
Single row functions
Soumyajit Dutta
 
Les03
Les03Les03
Les03
Abrianto Nugraha
 
Les03[1] Single-Row Functions
Les03[1] Single-Row FunctionsLes03[1] Single-Row Functions
Les03[1] Single-Row Functions
siavosh kaviani
 
Les03.pptx
Les03.pptxLes03.pptx
Les03.pptx
NishaTariq1
 
les05singlerowfunctiononoracledatabase.ppt
les05singlerowfunctiononoracledatabase.pptles05singlerowfunctiononoracledatabase.ppt
les05singlerowfunctiononoracledatabase.ppt
siddigzain606
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
Syed Zaid Irshad
 
Day1Structured_Query_Lang3For PL SQL Notes.ppt
Day1Structured_Query_Lang3For PL SQL Notes.pptDay1Structured_Query_Lang3For PL SQL Notes.ppt
Day1Structured_Query_Lang3For PL SQL Notes.ppt
consravs
 
Les03
Les03Les03
Les03
Sudharsan S
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03
Angel G Diaz
 
Les09.ppt
Les09.pptLes09.ppt
Les09.ppt
PrathameshSingh15
 
Les03
Les03Les03
Les03
Vijay Kumar
 
Dbms oracle
Dbms oracle Dbms oracle
Dbms oracle
Abrar ali
 
plsql Les09
 plsql Les09 plsql Les09
plsql Les09
sasa_eldoby
 
Basics of SQL understanding the database.pptx
Basics of SQL understanding the database.pptxBasics of SQL understanding the database.pptx
Basics of SQL understanding the database.pptx
vikkylion302
 
e computer notes - Single row functions
e computer notes - Single row functionse computer notes - Single row functions
e computer notes - Single row functions
ecomputernotes
 
Database Management Systems SQL And DDL language
Database Management Systems SQL And DDL languageDatabase Management Systems SQL And DDL language
Database Management Systems SQL And DDL language
HSibghatUllah
 
Les01 Writing BAsic SQL SELECT Statement.ppt
Les01 Writing BAsic SQL SELECT Statement.pptLes01 Writing BAsic SQL SELECT Statement.ppt
Les01 Writing BAsic SQL SELECT Statement.ppt
DrZeeshanBhatti
 
Les02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.pptLes02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.ppt
DrZeeshanBhatti
 
Les03 Single Row Functions in Oracle and SQL.ppt
Les03 Single Row Functions in Oracle and SQL.pptLes03 Single Row Functions in Oracle and SQL.ppt
Les03 Single Row Functions in Oracle and SQL.ppt
DrZeeshanBhatti
 
Built in functions singlerow & group.ppt
Built in functions singlerow & group.pptBuilt in functions singlerow & group.ppt
Built in functions singlerow & group.ppt
sivamathi12
 
Les03[1] Single-Row Functions
Les03[1] Single-Row FunctionsLes03[1] Single-Row Functions
Les03[1] Single-Row Functions
siavosh kaviani
 
les05singlerowfunctiononoracledatabase.ppt
les05singlerowfunctiononoracledatabase.pptles05singlerowfunctiononoracledatabase.ppt
les05singlerowfunctiononoracledatabase.ppt
siddigzain606
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
Syed Zaid Irshad
 
Day1Structured_Query_Lang3For PL SQL Notes.ppt
Day1Structured_Query_Lang3For PL SQL Notes.pptDay1Structured_Query_Lang3For PL SQL Notes.ppt
Day1Structured_Query_Lang3For PL SQL Notes.ppt
consravs
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03
Angel G Diaz
 
Dbms oracle
Dbms oracle Dbms oracle
Dbms oracle
Abrar ali
 
Basics of SQL understanding the database.pptx
Basics of SQL understanding the database.pptxBasics of SQL understanding the database.pptx
Basics of SQL understanding the database.pptx
vikkylion302
 
e computer notes - Single row functions
e computer notes - Single row functionse computer notes - Single row functions
e computer notes - Single row functions
ecomputernotes
 
Database Management Systems SQL And DDL language
Database Management Systems SQL And DDL languageDatabase Management Systems SQL And DDL language
Database Management Systems SQL And DDL language
HSibghatUllah
 
Les01 Writing BAsic SQL SELECT Statement.ppt
Les01 Writing BAsic SQL SELECT Statement.pptLes01 Writing BAsic SQL SELECT Statement.ppt
Les01 Writing BAsic SQL SELECT Statement.ppt
DrZeeshanBhatti
 
Les02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.pptLes02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.ppt
DrZeeshanBhatti
 
Ad

More from Salman Memon (20)

PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy Demo
Salman Memon
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
Salman Memon
 
How to Use Dreamweaver cs6
How to Use Dreamweaver cs6 How to Use Dreamweaver cs6
How to Use Dreamweaver cs6
Salman Memon
 
what is programming and its clear Concepts to the point
what is programming and its clear Concepts to the point what is programming and its clear Concepts to the point
what is programming and its clear Concepts to the point
Salman Memon
 
Working with variables in PHP
Working with variables in PHPWorking with variables in PHP
Working with variables in PHP
Salman Memon
 
Web forms and html (lect 5)
Web forms and html (lect 5)Web forms and html (lect 5)
Web forms and html (lect 5)
Salman Memon
 
Web forms and html (lect 4)
Web forms and html (lect 4)Web forms and html (lect 4)
Web forms and html (lect 4)
Salman Memon
 
Web forms and html (lect 3)
Web forms and html (lect 3)Web forms and html (lect 3)
Web forms and html (lect 3)
Salman Memon
 
Web forms and html (lect 2)
Web forms and html (lect 2)Web forms and html (lect 2)
Web forms and html (lect 2)
Salman Memon
 
Web forms and html (lect 1)
Web forms and html (lect 1)Web forms and html (lect 1)
Web forms and html (lect 1)
Salman Memon
 
Managing in the Future Enterprise
Managing in the Future EnterpriseManaging in the Future Enterprise
Managing in the Future Enterprise
Salman Memon
 
Overview of Technology Management
Overview of Technology ManagementOverview of Technology Management
Overview of Technology Management
Salman Memon
 
Align Information Technology and Business Strategy
Align Information Technology and Business Strategy Align Information Technology and Business Strategy
Align Information Technology and Business Strategy
Salman Memon
 
WHITE BOX & BLACK BOX TESTING IN DATABASE
WHITE BOX & BLACK BOXTESTING IN DATABASEWHITE BOX & BLACK BOXTESTING IN DATABASE
WHITE BOX & BLACK BOX TESTING IN DATABASE
Salman Memon
 
Email security netwroking
Email security  netwrokingEmail security  netwroking
Email security netwroking
Salman Memon
 
Email security - Netwroking
Email security - Netwroking Email security - Netwroking
Email security - Netwroking
Salman Memon
 
Query decomposition in data base
Query decomposition in data baseQuery decomposition in data base
Query decomposition in data base
Salman Memon
 
Time Management
Time Management Time Management
Time Management
Salman Memon
 
Multimedea device and routes
Multimedea device and routesMultimedea device and routes
Multimedea device and routes
Salman Memon
 
Hash function
Hash function Hash function
Hash function
Salman Memon
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy Demo
Salman Memon
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
Salman Memon
 
How to Use Dreamweaver cs6
How to Use Dreamweaver cs6 How to Use Dreamweaver cs6
How to Use Dreamweaver cs6
Salman Memon
 
what is programming and its clear Concepts to the point
what is programming and its clear Concepts to the point what is programming and its clear Concepts to the point
what is programming and its clear Concepts to the point
Salman Memon
 
Working with variables in PHP
Working with variables in PHPWorking with variables in PHP
Working with variables in PHP
Salman Memon
 
Web forms and html (lect 5)
Web forms and html (lect 5)Web forms and html (lect 5)
Web forms and html (lect 5)
Salman Memon
 
Web forms and html (lect 4)
Web forms and html (lect 4)Web forms and html (lect 4)
Web forms and html (lect 4)
Salman Memon
 
Web forms and html (lect 3)
Web forms and html (lect 3)Web forms and html (lect 3)
Web forms and html (lect 3)
Salman Memon
 
Web forms and html (lect 2)
Web forms and html (lect 2)Web forms and html (lect 2)
Web forms and html (lect 2)
Salman Memon
 
Web forms and html (lect 1)
Web forms and html (lect 1)Web forms and html (lect 1)
Web forms and html (lect 1)
Salman Memon
 
Managing in the Future Enterprise
Managing in the Future EnterpriseManaging in the Future Enterprise
Managing in the Future Enterprise
Salman Memon
 
Overview of Technology Management
Overview of Technology ManagementOverview of Technology Management
Overview of Technology Management
Salman Memon
 
Align Information Technology and Business Strategy
Align Information Technology and Business Strategy Align Information Technology and Business Strategy
Align Information Technology and Business Strategy
Salman Memon
 
WHITE BOX & BLACK BOX TESTING IN DATABASE
WHITE BOX & BLACK BOXTESTING IN DATABASEWHITE BOX & BLACK BOXTESTING IN DATABASE
WHITE BOX & BLACK BOX TESTING IN DATABASE
Salman Memon
 
Email security netwroking
Email security  netwrokingEmail security  netwroking
Email security netwroking
Salman Memon
 
Email security - Netwroking
Email security - Netwroking Email security - Netwroking
Email security - Netwroking
Salman Memon
 
Query decomposition in data base
Query decomposition in data baseQuery decomposition in data base
Query decomposition in data base
Salman Memon
 
Multimedea device and routes
Multimedea device and routesMultimedea device and routes
Multimedea device and routes
Salman Memon
 

Recently uploaded (20)

IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 

Single-Row Functions in orcale Data base

  • 1. 3 Copyright © Oracle Corporation, 2001. All rights reserved. Single-Row Functions
  • 2. 3-2 Copyright © Oracle Corporation, 2001. All rights reserved. Objectives After completing this lesson, you should be able to do the following: • Describe various types of functions available in SQL • Use character, number, and date functions in SELECT statements • Describe the use of conversion functions
  • 3. 3-3 Copyright © Oracle Corporation, 2001. All rights reserved. SQL Functions FunctionFunction Input arg 1arg 1 arg 2arg 2 argarg nn Function performs action Output ResultResult valuevalue
  • 4. 3-4 Copyright © Oracle Corporation, 2001. All rights reserved. Two Types of SQL Functions FunctionsFunctions Single-rowSingle-row functionsfunctions Multiple-rowMultiple-row functionsfunctions
  • 5. 3-5 Copyright © Oracle Corporation, 2001. All rights reserved. Single-Row Functions Single row functions: • Manipulate data items • Accept arguments and return one value • Act on each row returned • Return one result per row • May modify the data type • Can be nested • Accept arguments which can be a column or an expression function_name [(arg1, arg2,...)]function_name [(arg1, arg2,...)]
  • 6. 3-6 Copyright © Oracle Corporation, 2001. All rights reserved. Single-Row Functions ConversionConversion CharacterCharacter NumberNumber DateDate GeneralGeneral Single-rowSingle-row functionsfunctions
  • 7. 3-7 Copyright © Oracle Corporation, 2001. All rights reserved. Character Functions CharacterCharacter functionsfunctions LOWER UPPER INITCAP CONCAT SUBSTR LENGTH INSTR LPAD | RPAD TRIM REPLACE Case-manipulationCase-manipulation functionsfunctions Character-manipulationCharacter-manipulation functionsfunctions
  • 8. 3-9 Copyright © Oracle Corporation, 2001. All rights reserved. Function Result Case Manipulation Functions These functions convert case for character strings. LOWER('SQL Course') UPPER('SQL Course') INITCAP('SQL Course') sql course SQL COURSE Sql Course
  • 9. 3-10 Copyright © Oracle Corporation, 2001. All rights reserved. Using Case Manipulation Functions Display the employee number, name, and department number for employee Higgins: SELECT employee_id, last_name, department_id FROM employees WHERE last_name = 'higgins'; no rows selectedno rows selected SELECT employee_id, last_name, department_id FROM employees WHERE last_name = 'higgins'; no rows selectedno rows selected SELECT employee_id, last_name, department_id FROM employees WHERE LOWER(last_name) = 'higgins';
  • 10. 3-11 Copyright © Oracle Corporation, 2001. All rights reserved. CONCAT('Hello', 'World') SUBSTR('HelloWorld',1,5) LENGTH('HelloWorld') INSTR('HelloWorld', 'W') LPAD(salary,10,'*') RPAD(salary, 10, '*') TRIM('H' FROM 'HelloWorld') HelloWorld Hello 10 6 *****24000 24000***** elloWorld Function Result Character-Manipulation Functions These functions manipulate character strings:
  • 11. 3-12 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT employee_id, CONCAT(first_name, last_name) NAME, job_id, LENGTH (last_name), INSTR(last_name, 'a') "Contains 'a'?" FROM employees WHERE SUBSTR(job_id, 4) = 'REP'; Using the Character-Manipulation Functions 1 2 31 2 3
  • 12. 3-13 Copyright © Oracle Corporation, 2001. All rights reserved. Number Functions • ROUND: Rounds value to specified decimal ROUND(45.926, 2) 45.93 • TRUNC: Truncates value to specified decimal TRUNC(45.926, 2) 45.92 • MOD: Returns remainder of division MOD(1600, 300) 100
  • 13. 3-14 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT ROUND(45.923,2), ROUND(45.923,0), ROUND(45.923,-1) FROM DUAL; Using the ROUND Function DUAL is a dummy table you can use to view results from functions and calculations. 1 2 3 31 2
  • 14. 3-15 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT TRUNC(45.923,2), TRUNC(45.923), TRUNC(45.923,-2) FROM DUAL; Using the TRUNC Function 31 2 1 2 3
  • 15. 3-16 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT last_name, salary, MOD(salary, 5000) FROM employees WHERE job_id = 'SA_REP'; Using the MOD Function Calculate the remainder of a salary after it is divided by 5000 for all employees whose job title is sales representative.
  • 16. 3-17 Copyright © Oracle Corporation, 2001. All rights reserved. Working with Dates • Oracle database stores dates in an internal numeric format: century, year, month, day, hours, minutes, seconds. • The default date display format is DD-MON-RR. – Allows you to store 21st century dates in the 20th century by specifying only the last two digits of the year. – Allows you to store 20th century dates in the 21st century in the same way. SELECT last_name, hire_date FROM employees WHERE last_name like ''G%';';
  • 17. 3-18 Copyright © Oracle Corporation, 2001. All rights reserved. Working with Dates SYSDATE is a function that returns: • Date • Time
  • 18. 3-19 Copyright © Oracle Corporation, 2001. All rights reserved. Arithmetic with Dates • Add or subtract a number to or from a date for a resultant date value. • Subtract two dates to find the number of days between those dates. • Add hours to a date by dividing the number of hours by 24.
  • 19. 3-20 Copyright © Oracle Corporation, 2001. All rights reserved. Using Arithmetic Operators with Dates SELECT last_name, (SYSDATE-hire_date)/7 AS WEEKS FROM employees WHERE department_id = 90;
  • 20. 3-21 Copyright © Oracle Corporation, 2001. All rights reserved. Date Functions Number of months between two dates MONTHS_BETWEEN ADD_MONTHS NEXT_DAY LAST_DAY ROUND TRUNC Add calendar months to date Next day of the date specified Last day of the month Round date Truncate date Function Description
  • 21. 3-22 Copyright © Oracle Corporation, 2001. All rights reserved. • MONTHS_BETWEEN ('01-SEP-95','11-JAN-94') Using Date Functions • ADD_MONTHS ('11-JAN-94',6) • NEXT_DAY ('01-SEP-95','FRIDAY') • LAST_DAY('01-FEB-95') 19.6774194 '11-JUL-94' '08-SEP-95' '28-FEB-95'
  • 22. 3-23 Copyright © Oracle Corporation, 2001. All rights reserved. • ROUND(SYSDATE,'MONTH') 01-AUG-95 • ROUND(SYSDATE ,'YEAR') 01-JAN-96 • TRUNC(SYSDATE ,'MONTH') 01-JUL-95 • TRUNC(SYSDATE ,'YEAR') 01-JAN-95 Using Date Functions Assume SYSDATE = '25-JUL-95':
  • 23. 3-24 Copyright © Oracle Corporation, 2001. All rights reserved. Practice 3, Part One: Overview This practice covers the following topics: • Writing a query that displays the current date • Creating queries that require the use of numeric, character, and date functions • Performing calculations of years and months of service for an employee
  • 24. 3-25 Copyright © Oracle Corporation, 2001. All rights reserved. Conversion Functions Implicit data typeImplicit data type conversionconversion Explicit data typeExplicit data type conversionconversion Data typeData type conversionconversion
  • 25. 3-26 Copyright © Oracle Corporation, 2001. All rights reserved. Implicit Data Type Conversion For assignments, the Oracle server can automatically convert the following: VARCHAR2 or CHAR From To VARCHAR2 or CHAR NUMBER DATE NUMBER DATE VARCHAR2 VARCHAR2
  • 26. 3-27 Copyright © Oracle Corporation, 2001. All rights reserved. Implicit Data Type Conversion For expression evaluation, the Oracle Server can automatically convert the following: VARCHAR2 or CHAR From To VARCHAR2 or CHAR NUMBER DATE
  • 27. 3-28 Copyright © Oracle Corporation, 2001. All rights reserved. Explicit Data Type Conversion NUMBER CHARACTER TO_CHAR TO_NUMBER DATE TO_CHAR TO_DATE
  • 28. 3-29 Copyright © Oracle Corporation, 2001. All rights reserved. Explicit Data Type Conversion NUMBER CHARACTER TO_CHAR TO_NUMBER DATE TO_CHAR TO_DATE
  • 29. 3-31 Copyright © Oracle Corporation, 2001. All rights reserved. Using the TO_CHAR Function with Dates The format model: • Must be enclosed in single quotation marks and is case sensitive • Can include any valid date format element • Has an fm element to remove padded blanks or suppress leading zeros • Is separated from the date value by a comma TO_CHAR(date, 'format_model')TO_CHAR(date, 'format_model')
  • 30. 3-32 Copyright © Oracle Corporation, 2001. All rights reserved. YYYY Elements of the Date Format Model YEAR MM MONTH DY DAY Full year in numbers Year spelled out Two-digit value for month Three-letter abbreviation of the day of the week Full name of the day of the week Full name of the month MON Three-letter abbreviation of the month DD Numeric day of the month
  • 31. 3-34 Copyright © Oracle Corporation, 2001. All rights reserved. Elements of the Date Format Model • Time elements format the time portion of the date. • Add character strings by enclosing them in double quotation marks. • Number suffixes spell out numbers. HH24:MI:SS AM 15:45:32 PM DD "of" MONTH 12 of OCTOBER ddspth fourteenth
  • 32. 3-36 Copyright © Oracle Corporation, 2001. All rights reserved. Using the TO_CHAR Function with Dates SELECT last_name, TO_CHAR(hire_date, 'fmDD Month YYYY') AS HIREDATE FROM employees; …
  • 33. 3-37 Copyright © Oracle Corporation, 2001. All rights reserved. Using the TO_CHAR Function with Numbers These are some of the format elements you can use with the TO_CHAR function to display a number value as a character: TO_CHAR(number, 'format_model')TO_CHAR(number, 'format_model') 9 0 $ L . , Represents a number Forces a zero to be displayed Places a floating dollar sign Uses the floating local currency symbol Prints a decimal point Prints a thousand indicator
  • 34. 3-38 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT TO_CHAR(salary, '$99,999.00') SALARY FROM employees WHERE last_name = 'Ernst'; Using the TO_CHAR Function with Numbers
  • 35. 3-39 Copyright © Oracle Corporation, 2001. All rights reserved. Using the TO_NUMBER and TO_DATE Functions • Convert a character string to a number format using the TO_NUMBER function: • Convert a character string to a date format using the TO_DATE function: • These functions have an fx modifier. This modifier specifies the exact matching for the character argument and date format model of a TO_DATE function TO_NUMBER(char[, 'format_model'])TO_NUMBER(char[, 'format_model']) TO_DATE(char[, 'format_model'])TO_DATE(char[, 'format_model'])
  • 36. 3-40 Copyright © Oracle Corporation, 2001. All rights reserved. Using the TO_NUMBER and TO_DATE Functions • Convert a character string to a number format using the TO_NUMBER function: • Convert a character string to a date format using the TO_DATE function: • These functions have an fx modifier. This modifier specifies the exact matching for the character argument and date format model of a TO_DATE function TO_NUMBER(char[, 'format_model'])TO_NUMBER(char[, 'format_model']) TO_DATE(char[, 'format_model'])TO_DATE(char[, 'format_model'])
  • 37. 3-41 Copyright © Oracle Corporation, 2001. All rights reserved. RR Date Format Current Year 1995 1995 2001 2001 Specified Date 27-OCT-95 27-OCT-17 27-OCT-17 27-OCT-95 RR Format 1995 2017 2017 1995 YY Format 1995 1917 2017 2095 If two digits of the current year are: 0–49 0–49 50–99 50–99 The return date is in the current century The return date is in the century after the current one The return date is in the century before the current one The return date is in the current century If the specified two-digit year is:
  • 38. 3-42 Copyright © Oracle Corporation, 2001. All rights reserved. Example of RR Date Format To find employees hired prior to 1990, use the RR format, which produces the same results whether the command is run in 1999 or now: SELECT last_name, TO_CHAR(hire_date, 'DD-Mon-YYYY') FROM employees WHERE hire_date < TO_DATE('01-Jan-90', 'DD-Mon-RR');
  • 39. 3-43 Copyright © Oracle Corporation, 2001. All rights reserved. Nesting Functions • Single-row functions can be nested to any level. • Nested functions are evaluated from deepest level to the least deep level. F3(F2(F1(col,arg1),arg2),arg3) Step 1 = Result 1 Step 2 = Result 2 Step 3 = Result 3
  • 40. 3-44 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT last_name, NVL(TO_CHAR(manager_id), 'No Manager') FROM employees WHERE manager_id IS NULL; Nesting Functions
  • 41. 3-45 Copyright © Oracle Corporation, 2001. All rights reserved. General Functions These functions work with any data type and pertain to using nulls. • NVL (expr1, expr2) • NVL2 (expr1, expr2, expr3) • NULLIF (expr1, expr2) • COALESCE (expr1, expr2, ..., exprn)
  • 42. 3-46 Copyright © Oracle Corporation, 2001. All rights reserved. NVL Function Converts a null to an actual value. • Data types that can be used are date, character, and number. • Data types must match: – NVL(commission_pct,0) – NVL(hire_date,'01-JAN-97') – NVL(job_id,'No Job Yet')
  • 43. 3-47 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT last_name, salary, NVL(commission_pct, 0), (salary*12) + (salary*12*NVL(commission_pct, 0)) AN_SAL FROM employees; Using the NVL Function … 1 2 1 2
  • 44. 3-48 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT last_name, salary, commission_pct, NVL2(commission_pct, 'SAL+COMM', 'SAL') income FROM employees WHERE department_id IN (50, 80); Using the NVL2 Function 1 2 1 2
  • 45. 3-49 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT first_name, LENGTH(first_name) "expr1", last_name, LENGTH(last_name) "expr2", NULLIF(LENGTH(first_name), LENGTH(last_name)) result FROM employees; Using the NULLIF Function … 1 2 3 1 2 3
  • 46. 3-50 Copyright © Oracle Corporation, 2001. All rights reserved. Using the COALESCE Function • The advantage of the COALESCE function over the NVL function is that the COALESCE function can take multiple alternate values. • If the first expression is not null, it returns that expression; otherwise, it does a COALESCE of the remaining expressions.
  • 47. 3-51 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT last_name, COALESCE(commission_pct, salary, 10) comm FROM employees ORDER BY commission_pct; Using the COALESCE Function …
  • 48. 3-52 Copyright © Oracle Corporation, 2001. All rights reserved. Conditional Expressions • Provide the use of IF-THEN-ELSE logic within a SQL statement • Use two methods: – CASE expression – DECODE function
  • 49. 3-53 Copyright © Oracle Corporation, 2001. All rights reserved. The CASE Expression Facilitates conditional inquiries by doing the work of an IF-THEN-ELSE statement: CASE expr WHEN comparison_expr1 THEN return_expr1 [WHEN comparison_expr2 THEN return_expr2 WHEN comparison_exprn THEN return_exprn ELSE else_expr] END CASE expr WHEN comparison_expr1 THEN return_expr1 [WHEN comparison_expr2 THEN return_expr2 WHEN comparison_exprn THEN return_exprn ELSE else_expr] END
  • 50. 3-54 Copyright © Oracle Corporation, 2001. All rights reserved. SELECT last_name, job_id, salary, CASE job_id WHEN 'IT_PROG' THEN 1.10*salary WHEN 'ST_CLERK' THEN 1.15*salary WHEN 'SA_REP' THEN 1.20*salary ELSE salary END "REVISED_SALARY" FROM employees; Using the CASE Expression Facilitates conditional inquiries by doing the work of an IF-THEN-ELSE statement: … …
  • 51. 3-55 Copyright © Oracle Corporation, 2001. All rights reserved. The DECODE Function Facilitates conditional inquiries by doing the work of a CASE or IF-THEN-ELSE statement: DECODE(col|expression, search1, result1 [, search2, result2,...,] [, default]) DECODE(col|expression, search1, result1 [, search2, result2,...,] [, default])
  • 52. 3-56 Copyright © Oracle Corporation, 2001. All rights reserved. Using the DECODE Function SELECT last_name, job_id, salary, DECODE(job_id, 'IT_PROG', 1.10*salary, 'ST_CLERK', 1.15*salary, 'SA_REP', 1.20*salary, salary) REVISED_SALARY FROM employees; … …
  • 53. 3-57 Copyright © Oracle Corporation, 2001. All rights reserved. Using the DECODE Function SELECT last_name, salary, DECODE (TRUNC(salary/2000, 0), 0, 0.00, 1, 0.09, 2, 0.20, 3, 0.30, 4, 0.40, 5, 0.42, 6, 0.44, 0.45) TAX_RATE FROM employees WHERE department_id = 80; Display the applicable tax rate for each employee in department 80.
  • 54. 3-58 Copyright © Oracle Corporation, 2001. All rights reserved. Summary In this lesson, you should have learned how to: • Perform calculations on data using functions • Modify individual data items using functions • Manipulate output for groups of rows using functions • Alter date formats for display using functions • Convert column data types using functions • Use NVL functions • Use IF-THEN-ELSE logic
  • 55. 3-59 Copyright © Oracle Corporation, 2001. All rights reserved. Practice 3, Part Two: Overview This practice covers the following topics: • Creating queries that require the use of numeric, character, and date functions • Using concatenation with functions • Writing case-insensitive queries to test the usefulness of character functions • Performing calculations of years and months of service for an employee • Determining the review date for an employee
  • 56. 3-60 Copyright © Oracle Corporation, 2001. All rights reserved.
  • 57. 3-62 Copyright © Oracle Corporation, 2001. All rights reserved.

Editor's Notes

  • #2: Schedule:TimingTopic 55 minutesLecture 30 minutesPractice 85 minutesTotal
  • #3: Lesson Aim Functions make the basic query block more powerful and are used to manipulate data values. This is the first of two lessons that explore functions. It focuses on single-row character, number, and date functions, as well as those functions that convert data from one type to another, for example, character data to numeric data.
  • #4: SQL Functions Functions are a very powerful feature of SQL and can be used to do the following: Perform calculations on data Modify individual data items Manipulate output for groups of rows Format dates and numbers for display Convert column data types SQL functions sometimes take arguments and always return a value. Note: Most of the functions described in this lesson are specific to Oracle’s version of SQL. Instructor Note This lesson does not discuss all functions in great detail. It presents the most common functions with a brief explanation of them.
  • #5: SQL Functions (continued) There are two distinct types of functions: Single-row functions Multiple-row functions Single-Row Functions These functions operate on single rows only and return one result per row. There are different types of single-row functions. This lesson covers the following ones: Character Number Date Conversion Multiple-Row Functions Functions can manipulate groups of rows to give one result per group of rows. These functions are known as group functions. This is covered in a later lesson. For more information, see Oracle9i SQL Reference for the complete list of available functions and their syntax.
  • #6: Single-Row Functions Single-row functions are used to manipulate data items. They accept one or more arguments and return one value for each row returned by the query. An argument can be one of the following: User-supplied constant Variable value Column name Expression Features of single-row functions include: Acting on each row returned in the query Returning one result per row Possibly returning a data value of a different type than that referenced Possibly expecting one or more arguments Can be used in SELECT, WHERE, and ORDER BY clauses; can be nested In the syntax: function_nameis the name of the function. arg1, arg2is any argument to be used by the function. This can be represented by a column name or expression.
  • #7: Single-Row Functions (continued) This lesson covers the following single-row functions: Character functionsccept character input and can return both character and number values Number functionsAccept numeric input and return numeric values Date functionsOperate on values of the DATE data type (All date functions return a value of DATE data type except the MONTHS_BETWEEN function, which returns a number.) Conversion functionsConvert a value from one data type to another General functions: NVL NVL2 NULLIF COALSECE CASE DECODE
  • #10: Case Manipulation Functions LOWER, UPPER, and INITCAP are the three case-conversion functions. LOWERConverts mixed case or uppercase character strings to lowercase UPPERConverts mixed case or lowercase character strings to uppercase INITCAPConverts the first letter of each word to uppercase and remaining letters to lowercase SELECT &amp;apos;The job id for &amp;apos;||UPPER(last_name)||&amp;apos; is &amp;apos; ||LOWER(job_id) AS &amp;quot;EMPLOYEE DETAILS&amp;quot; FROM employees;
  • #11: Case Manipulation Functions (continued) The slide example displays the employee number, name, and department number of employee Higgins. The WHERE clause of the first SQL statement specifies the employee name as higgins. Because all the data in the EMPLOYEES table is stored in proper case, the name higgins does not find a match in the table, and no rows are selected. The WHERE clause of the second SQL statement specifies that the employee name in the EMPLOYEES table is compared to higgins, converting the LAST_NAME column to lowercase for comparison purposes. Since both names are lowercase now, a match is found and one row is selected. The WHERE clause can be rewritten in the following manner to produce the same result: ...WHERE last_name = &amp;apos;Higgins&amp;apos; The name in the output appears as it was stored in the database. To display the name capitalized, use the UPPER function in the SELECT statement. SELECT employee_id, UPPER(last_name), department_id FROM employees WHERE INITCAP(last_name) = &amp;apos;Higgins&amp;apos;;
  • #12: Character Manipulation Functions CONCAT, SUBSTR, LENGTH, INSTR, LPAD, RPAD, and TRIM are the character manipulation functions covered in this lesson. CONCATJoins values together (You are limited to using two parameters with CONCAT.) SUBSTRExtracts a string of determined length LENGTHShows the length of a string as a numeric value INSTRFinds numeric position of a named character LPADPads the character value right-justified RPAD: Pads the character value left-justified TRIM: Trims heading or trailing characters (or both) from a character string (If trim_character or trim_source is a character literal, you must enclose it in single quotes.) Instructor Note Be sure to point out RPAD to the students, because this function is needed in a practice exercise. Also, TRIM, which was a new function in Oracle8i, does the job of both the LTRIM and the RTRIM functions.
  • #13: Character-Manipulation Functions (continued) The slide example displays employee first names and last names joined together, the length of the employee last name, and the numeric position of the letter a in the employee last name for all employees who have the string REP contained in the job ID starting at the fourth position of the job ID. Example Modify the SQL statement on the slide to display the data for those employees whose last names end with an n. SELECT employee_id, CONCAT(first_name, last_name) NAME, LENGTH (last_name), INSTR(last_name, &amp;apos;a&amp;apos;) &amp;quot;Contains &amp;apos;a&amp;apos;?&amp;quot; FROM employees WHERE SUBSTR(last_name, -1, 1) = &amp;apos;n&amp;apos;;
  • #14: Number Functions Number functions accept numeric input and return numeric values. This section describes some of the number functions. Note: This list contains only some of the available number functions. For more information, see Oracle9i SQL Reference, “Number Functions.”
  • #15: ROUND Function The ROUND function rounds the column, expression, or value to n decimal places. If the second argument is 0 or is missing, the value is rounded to zero decimal places. If the second argument is 2, the value is rounded to two decimal places. Conversely, if the second argument is -2, the value is rounded to two decimal places to the left. The ROUND function can also be used with date functions. You will see examples later in this lesson. The DUAL Table The DUAL table is owned by the user SYS and can be accessed by all users. It contains one column, DUMMY, and one row with the value X. The DUAL table is useful when you want to return a value once only, for instance, the value of a constant, pseudocolumn, or expression that is not derived from a table with user data. The DUAL table is generally used for SELECT clause syntax completeness, because both SELECT and FROM clauses are mandatory, and several calculations do not need to select from actual tables.
  • #16: TRUNC Function The TRUNC function truncates the column, expression, or value to n decimal places. The TRUNC function works with arguments similar to those of the ROUND function. If the second argument is 0 or is missing, the value is truncated to zero decimal places. If the second argument is 2, the value is truncated to two decimal places. Conversely, if the second argument is -2, the value is truncated to two decimal places to the left. Like the ROUND function, the TRUNC function can be used with date functions.
  • #17: MOD Function The MOD function finds the remainder of value1 divided by value2. The slide example calculates the remainder of the salary after dividing it by 5,000 for all employees whose job ID is SA_REP. Note: The MOD function is often used to determine if a value is odd or even. Instructor Note (for page 3-17) You can change the default date display setting for a user session by executing the command: ALTER SESSION SET NLS_DATE_FORMAT = &amp;apos;date format model&amp;apos;; The DBA can set the date format for a database to a different format from the default. In either case, changing these settings is usually not a developer’s role.
  • #18: Oracle Date Format Oracle database stores dates in an internal numeric format, representing the century, year, month, day, hours, minutes, and seconds. The default display and input format for any date is DD-MON-RR. Valid Oracle dates are between January 1, 4712 B.C. and December 31, 9999 A.D. In the example in the slide, the HIRE_DATE for the employee Gietz is displayed in the default format DD-MON-RR. However, dates are not stored in the database in this format. All the components of the date and time are stored. So, although a HIRE_DATE such as 07-JUN-94 is displayed as day, month, and year, there is also time and century information associated with it. The complete data might be June 7th, 1994 5:10:43 p.m. This data is stored internally as follows: CENTURYYEARMONTHDAYHOURMINUTESECOND 1994060751043 Centuries and the Year 2000 The Oracle server is year 2000 compliant. When a record with a date column is inserted into a table, the century information is picked up from the SYSDATE function. However, when the date column is displayed on the screen, the century component is not displayed by default. The DATE data type always stores year information as a four-digit number internally: two digits for the century and two digits for the year. For example, the Oracle database stores the year as 1996 or 2001, and not just as 96 or 01.
  • #19: The SYSDATE Function SYSDATE is a date function that returns the current database server date and time. You can use SYSDATE just as you would use any other column name. For example, you can display the current date by selecting SYSDATE from a table. It is customary to select SYSDATE from a dummy table called DUAL. Example Display the current date using the DUAL table. SELECT SYSDATE FROM DUAL;
  • #20: Arithmetic with Dates Since the database stores dates as numbers, you can perform calculations using arithmetic operators such as addition and subtraction. You can add and subtract number constants as well as dates. You can perform the following operations:
  • #21: Arithmetic with Dates (continued) The example on the slide displays the last name and the number of weeks employed for all employees in department 90. It subtracts the date on which the employee was hired from the current date (SYSDATE) and divides the result by 7 to calculate the number of weeks that a worker has been employed. Note: SYSDATE is a SQL function that returns the current date and time. Your results may differ from the example. If a more current date is subtracted from an older date, the difference is a negative number.
  • #22: Date Functions Date functions operate on Oracle dates. All date functions return a value of DATE data type except MONTHS_BETWEEN, which returns a numeric value. MONTHS_BETWEEN(date1, date2)Finds the number of months between date1 and date2. The result can be positive or negative. If date1 is later than date2, the result is positive; if date1 is earlier than date2, the result is negative. The noninteger part of the result represents a portion of the month. ADD_MONTHS(date, n)Adds n number of calendar months to date. The value of n must be an integer and can be negative. NEXT_DAY(date, &amp;apos;char&amp;apos;)Finds the date of the next specified day of the week (&amp;apos;char&amp;apos;) following date. The value of char may be a number representing a day or a character string. LAST_DAY(date)Finds the date of the last day of the month that contains date. ROUND(date[,&amp;apos;fmt&amp;apos;])Returns date rounded to the unit specified by the format model fmt. If the format model fmt is omitted, date is rounded to the nearest day. TRUNC(date[, &amp;apos;fmt&amp;apos;])Returns date with the time portion of the day truncated to the unit specified by the format model fmt. If the format model fmt is omitted, date is truncated to the nearest day. This list is a subset of the available date functions. The format models are covered later in this lesson. Examples of format models are month and year.
  • #23: Date Functions (continued) For example, display the employee number, hire date, number of months employed, six-month review date, first Friday after hire date, and last day of the hire month for all employees employed for fewer than 36 months. SELECT employee_id, hire_date, MONTHS_BETWEEN (SYSDATE, hire_date) TENURE, ADD_MONTHS (hire_date, 6) REVIEW, NEXT_DAY (hire_date, &amp;apos;FRIDAY&amp;apos;), LAST_DAY(hire_date) FROM employees WHERE MONTHS_BETWEEN (SYSDATE, hire_date) &amp;lt; 36;
  • #24: Date Functions (continued) The ROUND and TRUNC functions can be used for number and date values. When used with dates, these functions round or truncate to the specified format model. Therefore, you can round dates to the nearest year or month. Example Compare the hire dates for all employees who started in 1997. Display the employee number, hire date, and start month using the ROUND and TRUNC functions. SELECT employee_id, hire_date, ROUND(hire_date, &amp;apos;MONTH&amp;apos;), TRUNC(hire_date, &amp;apos;MONTH&amp;apos;) FROM employees WHERE hire_date LIKE &amp;apos;%97&amp;apos;; Instructor Note If the format model is month, dates 1-15 result in the first day of the current month. Dates 16-31 result in the first day of the next month. If the format model is year, months 1-6 result with January 1st of the current year. Months 7-12 result in January 1st of the next year. This is a good point to break the lesson in half. Have the students do Practice 3 - Part 1 (1-5) now.
  • #25: Practice 3, Part One: Overview This practice is designed to give you a variety of exercises using different functions available for character, number, and date data types. Complete questions 1-5 at the end of this lesson.
  • #26: Conversion Functions In addition to Oracle data types, columns of tables in an Oracle9i database can be defined using ANSI, DB2, and SQL/DS data types. However, the Oracle server internally converts such data types to Oracle data types. In some cases, Oracle server uses data of one data type where it expects data of a different data type. When this happens, Oracle server can automatically convert the data to the expected data type. This data type conversion can be done implicitly by Oracle server, or explicitly by the user. Implicit data type conversions work according to the rules explained in the next two slides. Explicit data type conversions are done by using the conversion functions. Conversion functions convert a value from one data type to another. Generally, the form of the function names follows the convention data type TO data type. The first data type is the input data type; the last data type is the output. Note: Although implicit data type conversion is available, it is recommended that you do explicit data type conversion to ensure the reliability of your SQL statements.
  • #27: Implicit Data Type Conversion The assignment succeeds if the Oracle server can convert the data type of the value used in the assignment to that of the assignment target. Instructor Note There are several new data types available in the Oracle9i release pertaining to time. These include: TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE, INTERVAL YEAR, INTERVAL DAY. These are discussed later in the course. You can also refer students to the Oracle9i SQL Reference, “Basic Elements of Oracle SQL.”
  • #28: Implicit Data Type Conversion (continued) In general, the Oracle server uses the rule for expressions when a data type conversion is needed in places not covered by a rule for assignment conversions. Note: CHAR to NUMBER conversions succeed only if the character string represents a valid number. Instructor Note Implicit data conversion is not solely performed on the data types mentioned. Other implicit data conversions can also be done. For example, VARCHAR2 can be implicitly converted to ROWID.
  • #29: Explicit Data Type Conversion SQL provides three functions to convert a value from one data type to another:
  • #30: Explicit Data Type Conversion (continued)
  • #31: Explicit Data Type Conversion (continued) Note: The list of functions mentioned in this lesson includes only some of the available conversion functions. For more information, see Oracle9i SQL Reference, “Conversion Functions.”
  • #32: Displaying a Date in a Specific Format Previously, all Oracle date values were displayed in the DD-MON-YY format. You can use the TO_CHAR function to convert a date from this default format to one specified by you. Guidelines The format model must be enclosed in single quotation marks and is case sensitive. The format model can include any valid date format element. Be sure to separate the date value from the format model by a comma. The names of days and months in the output are automatically padded with blanks. To remove padded blanks or to suppress leading zeros, use the fill mode fm element. You can format the resulting character field with the iSQL*Plus COLUMN command covered in a later lesson. SELECT employee_id, TO_CHAR(hire_date, &amp;apos;MM/YY&amp;apos;) Month_Hired FROM employees WHERE last_name = &amp;apos;Higgins&amp;apos;;
  • #34: Sample Format Elements of Valid Date Formats Instructor Note Emphasize the format D, as the students need it for practice 10. The D format returns a value from 1 to 7 representing the day of the week. Depending on the NLS date setting options, the value 1 may represent Sunday or Monday. In the United States, the value 1 represents Sunday.
  • #35: Date Format Elements - Time Formats Use the formats listed in the following tables to display time information and literals and to change numerals to spelled numbers.
  • #36: Other Formats Specifying Suffixes to Influence Number Display
  • #37: The TO_CHAR Function with Dates The SQL statement on the slide displays the last names and hire dates for all the employees. The hire date appears as 17 June 1987. Example Modify the slide example to display the dates in a format that appears as Seventh of June 1994 12:00:00 AM. SELECT last_name, TO_CHAR(hire_date, &amp;apos;fmDdspth &amp;quot;of&amp;quot; Month YYYY fmHH:MI:SS AM&amp;apos;) HIREDATE FROM employees; Notice that the month follows the format model specified: in other words, the first letter is capitalized and the rest are lowercase.
  • #38: The TO_CHAR Function with Numbers When working with number values such as character strings, you should convert those numbers to the character data type using the TO_CHAR function, which translates a value of NUMBER data type to VARCHAR2 data type. This technique is especially useful with concatenation. Number Format Elements If you are converting a number to the character data type, you can use the following format elements:
  • #39: Guidelines The Oracle server displays a string of hash signs (#) in place of a whole number whose digits exceed the number of digits provided in the format model. The Oracle server rounds the stored decimal value to the number of decimal spaces provided in the format model. Instructor Note (for page 3-39) You can demonstrate the code using the fx modifier in the file 3_39n. Run the file with the fx modifier present, then remove the fx modifier and run the statement again.
  • #40: The TO_NUMBER and TO_DATE Functions You may want to convert a character string to either a number or a date. To accomplish this task, use the TO_NUMBER or TO_DATE functions. The format model you choose is based on the previously demonstrated format elements. The “fx” modifier specifies exact matching for the character argument and date format model of a TO_DATE function: Punctuation and quoted text in the character argument must exactly match (except for case) the corresponding parts of the format model. The character argument cannot have extra blanks. Without fx, Oracle ignores extra blanks. Numeric data in the character argument must have the same number of digits as the corresponding element in the format model. Without fx, numbers in the character argument can omit leading zeroes.
  • #41: The TO_NUMBER and TO_DATE Functions (continued) Example Display the names and hire dates of all the employees who joined on May 24, 1999. Because the fx modifier is used, an exact match is required and the spaces after the word ‘May’ are not recognized. SELECT last_name, hire_date FROM employees WHERE hire_date = TO_DATE(&amp;apos;May 24, 1999&amp;apos;, &amp;apos;fxMonth DD, YYYY&amp;apos;);
  • #42: The RR Date Format Element The RR date format is similar to the YY element, but you can use it to specify different centuries. You can use the RR date format element instead of YY, so that the century of the return value varies according to the specified two-digit year and the last two digits of the current year. The table on the slide summarizes the behavior of the RR element. Instructor Note RR is available in Oracle7, not Oracle version 6. NLS parameters can be added to the init.ora file to set default date formats and language names and abbreviations. For more information, see Oracle9i SQL Reference, “ALTER SESSION”. Demo: 3_hire.sql Purpose: To illustrate date format model elements.
  • #43: The RR Date Format Element Example To find employees who were hired prior to 1990, the RR format can be used. Since the year is now greater than 1999, the RR format interprets the year portion of the date from 1950 to 1999. The following command, on the other hand, results in no rows being selected because the YY format interprets the year portion of the date in the current century (2090). SELECT last_name, TO_CHAR(hire_date, &amp;apos;DD-Mon-yyyy&amp;apos;) FROM employees WHERE TO_DATE(hire_date, &amp;apos;DD-Mon-yy&amp;apos;) &amp;lt; &amp;apos;01-Jan-1990&amp;apos;; no rows selected
  • #44: Nesting Functions Single-row functions can be nested to any depth. Nested functions are evaluated from the innermost level to the outermost level. Some examples follow to show you the flexibility of these functions.
  • #45: Nesting Functions (continued) The slide example displays the head of the company, who has no manager. The evaluation of the SQL statement involves two steps: 1. Evaluate the inner function to convert a number value to a character string. Result1 = TO_CHAR(manager_id) 2. Evaluate the outer function to replace the null value with a text string. NVL(Result1, &amp;apos;No Manager&amp;apos;) The entire expression becomes the column heading because no column alias was given. Example Display the date of the next Friday that is six months from the hire date. The resulting date should appear as Friday, August 13th, 1999. Order the results by hire date. SELECT TO_CHAR(NEXT_DAY(ADD_MONTHS (hire_date, 6), &amp;apos;FRIDAY&amp;apos;), &amp;apos;fmDay, Month DDth, YYYY&amp;apos;) &amp;quot;Next 6 Month Review&amp;quot; FROM employees ORDER BY hire_date; Instructor Note Demo: 3_nest.sql Purpose: To illustrate nesting of several single row functions
  • #46: General Functions These functions work with any data type and pertain to the use of null values in the expression list. Note: For more information on the hundreds of functions available, see Oracle9i SQL Reference, “Functions.”
  • #47: The NVL Function To convert a null value to an actual value, use the NVL function. Syntax NVL (expr1, expr2) In the syntax: expr1 is the source value or expression that may contain a null expr2 is the target value for converting the null You can use the NVL function to convert any data type, but the return value is always the same as the data type of expr1. NVL Conversions for Various Data Types
  • #48: The NVL Function (continued) To calculate the annual compensation of all employees, you need to multiply the monthly salary by 12 and then add the commission percentage to it. SELECT last_name, salary, commission_pct, (salary*12) + (salary*12*commission_pct) AN_SAL FROM employees; Notice that the annual compensation is calculated only for those employees who earn a commission. If any column value in an expression is null, the result is null. To calculate values for all employees, you must convert the null value to a number before applying the arithmetic operator. In the example on the slide, the NVL function is used to convert null values to zero.
  • #49: The NVL2 Function The NVL2 function examines the first expression. If the first expression is not null, then the NVL2 function returns the second expression. If the first expression is null, then the third expression is returned. Syntax NVL(expr1, expr2, expr3) In the syntax: expr1 is the source value or expression that may contain null expr2 is the value returned if expr1 is not null expr3is the value returned if expr2 is null In the example shown, the COMMISSION_PCT column is examined. If a value is detected, the second expression of SAL+COMM is returned. If the COMMISSION_PCT column holds a null values, the third expression of SAL is returned. The argument expr1 can have any data type. The arguments expr2 and expr3 can have any data types except LONG. If the data types of expr2 and expr3 are different, The Oracle server converts expr3 to the data type of expr2 before comparing them unless expr3 is a null constant. In that case, a data type conversion is not necessary. The data type of the return value is always the same as the data type of expr2, unless expr2 is character data, in which case the return value’s data type is VARCHAR2.
  • #50: The NULLIF Function The NULLIF function compares two expressions. If they are equal, the function returns null. If they are not equal, the function returns the first expression. You cannot specify the literal NULL for first expression. Syntax NULLIF (expr1, expr2) In the syntax: expr1 is the source value compared to expr2 expr2 is the source value compared with expr1. (If it is not equal to expr1, expr1 is returned.) In the example shown, the job ID in the EMPLOYEES table is compared to the job ID in the JOB_HISTORY table for any employee who is in both tables. The output shows the employee’s current job. If the employee is listed more than once, that means the employee has held at least two jobs previously. Note: The NULLIF function is logically equivalent to the following CASE expression. The CASE expression is discussed in a subsequent page: CASE WHEN expr1 = expr 2 THEN NULL ELSE expr1 END
  • #51: The COALESCE Function The COALESCE function returns the first non-null expression in the list. Syntax COALESCE (expr1, expr2, ... exprn) In the syntax: expr1 returns this expression if it is not null expr2 returns this expression if the first expression is null and this expression is not null exprnreturns this expression if the preceding expressions are null
  • #52: The COALESCE Function (continued) In the example shown, if the COMMISSION_PCT value is not null, it is shown. If the COMMISSION_PCT value is null, then the SALARY is shown. If the COMMISSION_PCT and SALARY values are null, then the value 10 is shown.
  • #53: Conditional Expressions Two methods used to implement conditional processing (IF-THEN-ELSE logic) within a SQL statement are the CASE expression and the DECODE function. Note: The CASE expression is new in the Oracle9i Server release. The CASE expression complies with ANSI SQL; DECODE is specific to Oracle syntax.
  • #54: The CASE Expression CASE expressions let you use IF-THEN-ELSE logic in SQL statements without having to invoke procedures. In a simple CASE expression, Oracle searches for the first WHEN ... THEN pair for which expr is equal to comparison_expr and returns return_expr. If none of the WHEN ... THEN pairs meet this condition, and an ELSE clause exists, then Oracle returns else_expr. Otherwise, Oracle returns null. You cannot specify the literal NULL for all the return_exprs and the else_expr. All of the expressions ( expr, comparison_expr, and return_expr) must be of the same data type, which can be CHAR, VARCHAR2, NCHAR, or NVARCHAR2. Instructor Note There is also a searched CASE expression. Oracle searches from left to right until it finds an occurrence of a condition that is true, and then returns return_expr. If no condition is found to be true, and an ELSE clause exists, Oracle returns else_expr. Otherwise Oracle returns null. For more information, see Oracle9i SQL Reference, “Expressions.”
  • #55: Using the CASE Expression In the preceding SQL statement, the value of JOB_ID is decoded. If JOB_ID is IT_PROG, the salary increase is 10%; if JOB_ID is ST_CLERK, the salary increase is 15%; if JOB_ID is SA_REP, the salary increase is 20%. For all other job roles, there is no increase in salary. The same statement can be written with the DECODE function.
  • #56: The DECODE Function The DECODE function decodes an expression in a way similar to the IF-THEN-ELSE logic used in various languages. The DECODE function decodes expression after comparing it to each search value. If the expression is the same as search, result is returned. If the default value is omitted, a null value is returned where a search value does not match any of the result values.
  • #57: Using the DECODE Function In the preceding SQL statement, the value of JOB_ID is tested. If JOB_ID is IT_PROG, the salary increase is 10%; if JOB_ID is ST_CLERK, the salary increase is 15%; if JOB_ID is SA_REP, the salary increase is 20%. For all other job roles, there is no increase in salary. The same statement can be expressed in pseudocode as an IF-THEN-ELSE statement: IF job_id = &amp;apos;IT_PROG&amp;apos; THEN salary = salary*1.10 IF job_id = &amp;apos;ST_CLERK&amp;apos; THEN salary = salary*1.15 IF job_id = &amp;apos;SA_REP&amp;apos; THEN salary = salary*1.20 ELSE salary = salary
  • #58: Example This slide shows another example using the DECODE function. In this example, we determine the tax rate for each employee in department 80 based on the monthly salary. The tax rates are as per the values mentioned in the following data. Monthly Salary RangeRate $0.00 - 1999.9900% $2,000.00 - 3,999.9909% $4,000.00 - 5,999.9920% $6,000.00 - 7,999.9930% $8,000.00 - 9,999.9940% $10,000.00 - 11,999.9942% $12,200.00 - 13,999.9944% $14,000.00 or greater45%
  • #59: Single-Row Functions Single-row functions can be nested to any level. Single-row functions can manipulate the following: Character data: LOWER, UPPER, INITCAP, CONCAT, SUBSTR, INSTR, LENGTH Number data: ROUND, TRUNC, MOD Date data: MONTHS_BETWEEN, ADD_MONTHS, NEXT_DAY, LAST_DAY, ROUND, TRUNC Date values can also use arithmetic operators. Conversion functions can convert character, date, and numeric values: TO_CHAR, TO_DATE, TO_NUMBER There are several functions that pertain to nulls, including NVL, NVL2, NULLIF, and COALESCE. IF-THEN-ELSE logic can be applied within a SQL statement by using the CASE expression or the DECODE function. SYSDATE and DUAL SYSDATE is a date function that returns the current date and time. It is customary to select SYSDATE from a dummy table called DUAL.
  • #60: Practice 3, Part Two This practice is designed to give you a variety of exercises using different functions available for character, number, and date data types. Remember that for nested functions, the results are evaluated from the innermost function to the outermost function. Instructor Note This practice should be done in two parts. Part 1 contains questions 1-5 which cover the material from pages 1-23. Part 2 contains questions 6-14 and matches the material for the remainder of the lesson. Practice question 6: Be sure to tell the students that their results may differ from the one provided, because SYSDATE is used in the exercise. Instructor hint for practice question 10: The ORDER BY clause in the solution sorts on TO_CHAR(hiredate-1, &amp;apos;d&amp;apos;). The format element ‘d’ returns a ‘1’ for Sunday, ‘2’ for Monday, and so forth. The expression hiredate-1 effectively “shifts” each hiredate to the previous day, so that an employee hired on a Monday appears to have been hired on Sunday. The TO_CHAR function returns a ‘1’ for that employee and the result set is sorted beginning with those employees hired on Monday.
  • #61: Practice 3 - Part One 1.Write a query to display the current date. Label the column Date. 2.For each employee, display the employee number, last_name, salary, and salary increased by 15% and expressed as a whole number. Label the column New Salary. Place your SQL statement in a text file named lab3_2.sql. 3.Run your query in the file lab3_2.sql. 4.Modify your query lab3_2.sql to add a column that subtracts the old salary fromthe new salary. Label the column Increase. Save the contents of the file as lab3_4.sql. Run the revised query.
  • #62: Practice 3, Part One: Overview (continued) 5.Write a query that displays the employee’s last names with the first letter capitalized and all other letters lowercase, and the length of the names, for all employees whose name starts with J, A, or M. Give each column an appropriate label. Sort the results by the employees’ last names.
  • #63: Practice 3 - Part Two 6.For each employee, display the employee’s last name, and calculate the number of months between today and the date the employee was hired. Label the column MONTHS_WORKED. Order your results by the number of months employed. Round the number of months up to the closest whole number. Note: Your results will differ.
  • #64: Practice 3 - Part Two (continued) 7.Write a query that produces the following for each employee:&amp;lt;employee last name&amp;gt; earns &amp;lt;salary&amp;gt; monthly but wants &amp;lt;3 times salary&amp;gt;. Label the column Dream Salaries. If you have time, complete the following exercises: 8.Create a query to display the last name and salary for all employees. Format the salary to be 15characters long, left-padded with $. Label the column SALARY.
  • #65: Practice 3 - Part Two (continued) 9.Display each employee’s last name, hire date, and salary review date, which is the first Monday after six months of service. Label the column REVIEW. Format the dates to appear in the format similar to “Monday, the Thirty-First of July, 2000.” Display the last name, hire date, and day of the week on which the employee started. Labelthe column DAY. Order the results by the day of the week starting with Monday.
  • #66: Practice 3 - Part Two (continued) If you want an extra challenge, complete the following exercises: 11.Create a query that displays the employees’ last names and commission amounts. If an employee does not earn commission, put “No Commission.” Label the column COMM. 12.Create a query that displays the employees’ last names and indicates the amounts of their annual salaries with asterisks. Each asterisk signifies a thousand dollars. Sort the data in descending order of salary. Label the column EMPLOYEES_AND_THEIR_SALARIES.
  • #67: Practice 3 - Part Two (continued) 13. Using the DECODE function, write a query that displays the grade of all employees based on the value of the column JOB_ID, as per the following data: JobGrade AD_PRESA ST_MANB IT_PROGC SA_REPD ST_CLERKE None of the above0 14. Rewrite the statement in the preceding question using the CASE syntax.