[go: up one dir, main page]

0% found this document useful (0 votes)
11 views51 pages

Chapter 10

The document outlines the objectives and functions covered in Chapter 10 of Oracle 12c: SQL, focusing on single-row functions for manipulating character strings, numeric data, and dates. It details various functions such as UPPER, LOWER, SUBSTR, ROUND, and TO_DATE, along with their applications. Additionally, it discusses the use of regular expressions, handling NULL values, and the DUAL table for testing functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views51 pages

Chapter 10

The document outlines the objectives and functions covered in Chapter 10 of Oracle 12c: SQL, focusing on single-row functions for manipulating character strings, numeric data, and dates. It details various functions such as UPPER, LOWER, SUBSTR, ROUND, and TO_DATE, along with their applications. Additionally, it discusses the use of regular expressions, handling NULL values, and the DUAL table for testing functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 51

About the Presentations

• The presentations cover the objectives found in the


opening of each chapter.
• All chapter objectives are listed in the beginning of
each presentation.
• You may customize the presentations to fit your
class needs.
• Some figures from the chapters are included. A
complete set of images from the book can be found
on the Instructor Resources disc.
©2016. Cengage Learning. All rights reserved.
Oracle 12c: SQL

Chapter 10
Selected Single-Row Functions

©2016. Cengage Learning. All rights reserved.


Objectives
• Use the UPPER, LOWER, and INITCAP functions to change the
case of field values and character strings
• Manipulate character substrings with the SUBSTR and INSTR
functions
• Nest functions inside other functions
• Determine the length of a character string using the LENGTH
function
• Use the LPAD and RPAD functions to pad a string to a certain
width
• Use the LTRIM and RTRIM functions to remove specific
characters strings
• Substitute character string values with the REPLACE and
TRANSLATE functions

©2016. Cengage Learning. All rights reserved. 3


Objectives (continued)

• Round and truncate numeric data using the ROUND


and TRUNC functions
• Return the remainder only of a division operation using
the MOD function
• Use the ABS function to set numeric values as positive
• Use the POWER function to raise a number to a
specified power
• Calculate the number of months between two dates
using the MONTHS_BETWEEN function
• Manipulate date data using the ADD_MONTHS,
NEXT_DAY, LAST_DAY, and TO_DATE functions

©2016. Cengage Learning. All rights reserved. 4


Objectives (continued)
• Differentiate between CURRENT_DATE and SYSDATE
values
• Extend pattern matching capabilities with regular
expressions
• Identify and correct problems associated with calculations
involving NULL values using the NVL function
• Display dates and numbers in a specific format with the
TO_CHAR function
• Perform condition processing similar to an IF statement with
the DECODE function
• Use the SOUNDEX function to identify character phonetics
• Convert string values to numeric with the TO_NUMBER
function
• Use the DUAL table to test functions

©2016. Cengage Learning. All rights reserved. 5


Terminology
• Function – predefined block of code that accepts
arguments
• Single-row function – returns one row of results for
each record processed
• Multiple-row function – returns one result per group
of data processed (covered in the next chapter)

©2016. Cengage Learning. All rights reserved. 6


Types of Functions

©2016. Cengage Learning. All rights reserved. 7


Case Conversion Functions
• Case conversion functions alter the case of data
stored in a column or character string
– Used in a SELECT clause, they alter the appearance
of the data in the results
– Used in a WHERE clause, they alter the value for
comparison

©2016. Cengage Learning. All rights reserved. 8


LOWER Function

• Used to convert characters to lowercase


letters

©2016. Cengage Learning. All rights reserved. 9


UPPER Function
• Used to convert characters to uppercase letters
• It can be used in the same way as the LOWER function
– To affect the display of characters, it is used in a SELECT clause
– To modify the case of characters for a search condition, it is used in a WHERE clause
• The syntax for the UPPER function is UPPER(c)
– Where c is the character string or field to be converted into uppercase characters

©2016. Cengage Learning. All rights reserved. 10


INITCAP Function

• Used to convert characters to mixed case

©2016. Cengage Learning. All rights reserved. 11


Character Manipulation Functions

• Character manipulation functions manipulate data


by extracting substrings, counting the number of
characters, replacing strings, etc.

©2016. Cengage Learning. All rights reserved. 12


SUBSTR Function

• Used to return a substring, or portion of a string

©2016. Cengage Learning. All rights reserved. 13


INSTR Function

©2016. Cengage Learning. All rights reserved. 14


Nesting Functions

©2016. Cengage Learning. All rights reserved. 15


LENGTH Function

• Used to determine the number of characters in a


string

©2016. Cengage Learning. All rights reserved. 16


LPAD and RPAD Functions

• Used to pad, or fill in, a character string to a fixed


width

©2016. Cengage Learning. All rights reserved. 17


LTRIM and RTRIM Functions

• Used to remove a specific string of characters

©2016. Cengage Learning. All rights reserved. 18


REPLACE Function

• Substitutes a string with another specified string

©2016. Cengage Learning. All rights reserved. 19


TRANSLATE Function

©2016. Cengage Learning. All rights reserved. 20


CONCAT Function

• Used to concatenate two character strings

©2016. Cengage Learning. All rights reserved. 21


Number Functions
• Allow for manipulation of numeric data
– ROUND
– TRUNC
– MOD
– ABS

©2016. Cengage Learning. All rights reserved. 22


ROUND Function
• Used to round numeric columns to a stated precision

©2016. Cengage Learning. All rights reserved. 23


TRUNC Function
• Used to truncate a numeric value to a specific position

©2016. Cengage Learning. All rights reserved. 24


MOD Function

©2016. Cengage Learning. All rights reserved. 25


ABS Function

©2016. Cengage Learning. All rights reserved. 26


Date Functions
• Used to perform date calculations or format date
values
• Subtract date for number of days difference

©2016. Cengage Learning. All rights reserved. 27


MONTHS_BETWEEN Function

• Determines the number of months between


two dates

©2016. Cengage Learning. All rights reserved. 28


ADD_MONTHS Function

• Adds a specified number of months to a date

©2016. Cengage Learning. All rights reserved. 29


NEXT_DAY Function

• Determines the next occurrence of a


specified day of the week after a given date

©2016. Cengage Learning. All rights reserved. 30


TO_DATE Function

• Converts various date formats to the internal


format (DD-MON-YY) used by Oracle 11g

©2016. Cengage Learning. All rights reserved. 31


Format Model Elements - Dates

©2016. Cengage Learning. All rights reserved. 32


ROUND Function

©2016. Cengage Learning. All rights reserved. 33


TRUNC Function

©2016. Cengage Learning. All rights reserved. 34


Regular Expressions
• Regular expressions allow the description of
complex patterns in textual data

©2016. Cengage Learning. All rights reserved. 35


REGEXP_LIKE

©2016. Cengage Learning. All rights reserved. 36


Other Functions
• NVL
• NVL2
• TO_CHAR
• DECODE
• SOUNDEX

©2016. Cengage Learning. All rights reserved. 37


NVL Function
• Substitutes a value for a NULL value

©2016. Cengage Learning. All rights reserved. 38


NVL2 Function
• Allows different actions based on whether a value is
NULL

©2016. Cengage Learning. All rights reserved. 39


NULLIF Function

©2016. Cengage Learning. All rights reserved. 40


TO_CHAR Function
• Converts dates and numbers to a formatted
character string

©2016. Cengage Learning. All rights reserved. 41


Format Model Elements –
Time and Number

©2016. Cengage Learning. All rights reserved. 42


DECODE Function

• Determines action based upon values in a list

©2016. Cengage Learning. All rights reserved. 43


CASE Expression

©2016. Cengage Learning. All rights reserved. 44


SOUNDEX Function

• References phonetic representation of words

©2016. Cengage Learning. All rights reserved. 45


TO_NUMBER Function

©2016. Cengage Learning. All rights reserved. 46


DUAL Table
• Dummy table
• Consists of one column and one row
• Can be used for table reference in the FROM
clause

©2016. Cengage Learning. All rights reserved. 47


Using DUAL

©2016. Cengage Learning. All rights reserved. 48


Summary
• Single-row functions return a result for each row or
record processed
• Case conversion functions such as UPPER, LOWER,
and INITCAP can be used to alter the case of character
strings
• Character manipulation functions can be used to extract
substrings (portions of a string), identify the position of
a substring in a string, replace occurrences of a string
with another string, determine the length of a character
string, and trim spaces or characters from strings
• Nesting one function within another allows multiple
operations to be performed on data
©2016. Cengage Learning. All rights reserved. 49
Summary (continued)
• Simple number functions such as ROUND and TRUNC
can round or truncate a number on both the left and right
side of a decimal
• The MOD function is used to return the remainder of a
division operation
• Date functions can be used to perform calculations with
dates or to change the format of dates entered by a user
• Regular expressions enable complex pattern matching
operations
• The NVL, NVL2, and NULLIF functions are used to
address problems encountered with NULL values

©2016. Cengage Learning. All rights reserved. 50


Summary (continued)
• The TO_CHAR function lets a user present numeric
data and dates in a specific format
• The DECODE function allows an action to be taken to
be determined by a specific value
• The searched CASE expression enables you to
evaluate conditions to determine the resulting value
• The SOUNDEX function looks for records based on the
phonetic representation of characters
• The DUAL table can be helpful when testing functions

©2016. Cengage Learning. All rights reserved. 51

You might also like