introduction to oracle9i: sql1 selected single-row functions
Post on 21-Dec-2015
237 views
TRANSCRIPT
![Page 1: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/1.jpg)
Introduction to Oracle9i: SQL 1
Selected Single-Row Functions
![Page 2: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/2.jpg)
Introduction to Oracle9i: SQL 2
Chapter Objectives
• Use the UPPER, LOWER, and INITCAP functions to change the case of field values and character strings
• Extract a substring using the SUBSTR function
• Determine the length of a character string using the LENGTH function
![Page 3: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/3.jpg)
Introduction to Oracle9i: SQL 3
Chapter Objectives
• Use the LPAD and RPAD functions to pad a string to a desired width
• Use the LTRIM and RTRIM functions to remove specific characters strings
• Round and truncate numeric data using the ROUND and TRUNC functions
• Calculate the number of months between two dates using the MONTHS_BETWEEN function
![Page 4: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/4.jpg)
Introduction to Oracle9i: SQL 4
Chapter Objectives
• 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
• Determine the current date setting using the SYSDATE keyword
• Nest functions inside other functions• Identify when to use the DUAL table
![Page 5: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/5.jpg)
Introduction to Oracle9i: SQL 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
![Page 6: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/6.jpg)
Introduction to Oracle9i: SQL 6
Types of Functions
![Page 7: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/7.jpg)
Introduction to Oracle9i: SQL 7
Case Conversion Functions
Alter the case of data stored in a column or character string
![Page 8: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/8.jpg)
Introduction to Oracle9i: SQL 8
LOWER Function
Used to convert characters to lower-case letters
![Page 9: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/9.jpg)
Introduction to Oracle9i: SQL 9
UPPER Function
Used to convert characters to upper-case letters
![Page 10: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/10.jpg)
Introduction to Oracle9i: SQL 10
INITCAP Function
Used to convert characters to mixed-case
![Page 11: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/11.jpg)
Introduction to Oracle9i: SQL 11
Character Manipulation Functions
Manipulates data by extracting substrings, counting number of characters, replacing strings, etc.
![Page 12: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/12.jpg)
Introduction to Oracle9i: SQL 12
SUBSTR Function
Used to return a substring, or portion of a string
![Page 13: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/13.jpg)
Introduction to Oracle9i: SQL 13
LENGTH Function
Used to determine the number of characters in a string
![Page 14: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/14.jpg)
Introduction to Oracle9i: SQL 14
LPAD and RPAD Functions
Used to pad, or fill in, a character string to a fixed width
![Page 15: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/15.jpg)
Introduction to Oracle9i: SQL 15
LTRIM and RTRIM Functions
Used to remove a specific string of characters
![Page 16: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/16.jpg)
Introduction to Oracle9i: SQL 16
REPLACE Function
Substitutes a string with another specified string
![Page 17: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/17.jpg)
Introduction to Oracle9i: SQL 17
CONCAT Function
Used to concatenate two character strings
![Page 18: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/18.jpg)
Introduction to Oracle9i: SQL 18
Number Functions
Allows for manipulation of numeric data
![Page 19: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/19.jpg)
Introduction to Oracle9i: SQL 19
ROUND Function
Used to round numeric columns to a stated precision
![Page 20: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/20.jpg)
Introduction to Oracle9i: SQL 20
TRUNC Function
Used to truncate a numeric value to a specific position
![Page 21: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/21.jpg)
Introduction to Oracle9i: SQL 21
Date Functions
Used to perform date calculations or format date values
![Page 22: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/22.jpg)
Introduction to Oracle9i: SQL 22
MONTHS_BETWEEN Function
Determines the number of months between two dates
![Page 23: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/23.jpg)
Introduction to Oracle9i: SQL 23
ADD_MONTHS Function
Adds a specified number of months to a date
![Page 24: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/24.jpg)
Introduction to Oracle9i: SQL 24
NEXT_DAY Function
Determines the next occurrence of a specified day of the week after a given date
![Page 25: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/25.jpg)
Introduction to Oracle9i: SQL 25
TO_DATE Function
Converts various date formats to the internal format (DD-MON-YYYY) used by Oracle9i
![Page 26: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/26.jpg)
Introduction to Oracle9i: SQL 26
Format Model Elements - Dates
![Page 27: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/27.jpg)
Introduction to Oracle9i: SQL 27
NVL Function
Substitutes a value for a NULL value
![Page 28: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/28.jpg)
Introduction to Oracle9i: SQL 28
NVL2 Function
Allows different actions based on whether a value is NULL
![Page 29: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/29.jpg)
Introduction to Oracle9i: SQL 29
TO_CHAR Function//
Converts dates and numbers to a formatted character string
![Page 30: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/30.jpg)
Introduction to Oracle9i: SQL 30
Format Model Elements – Time and Number
![Page 31: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/31.jpg)
Introduction to Oracle9i: SQL 31
Other Functions
• NVL
• NVL2
• TO_CHAR
• DECODE
• SOUNDEX
![Page 32: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/32.jpg)
Introduction to Oracle9i: SQL 32
DECODE Function
Determines action based upon values in a list
![Page 33: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/33.jpg)
Introduction to Oracle9i: SQL 33
SOUNDEX Function
References phonetic representation of words
![Page 34: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/34.jpg)
Introduction to Oracle9i: SQL 34
Nesting Functions
• One function is used as an argument inside another function
• Must include all arguments for each function • Inner function is resolved first, then outer function
![Page 35: Introduction to Oracle9i: SQL1 Selected Single-Row Functions](https://reader030.vdocument.in/reader030/viewer/2022012902/56649d585503460f94a37271/html5/thumbnails/35.jpg)
Introduction to Oracle9i: SQL 35
DUAL Table
• Dummy table• Consists of one column and one row• Can be used for table reference in the FROM
clause