350 likes | 485 Views
Chapter 5 Selected Single-Row Functions. 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 .
E N D
Chapter 5Selected Single-Row Functions Oracle9i: SQL
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 Oracle9i: SQL
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 Oracle9i: SQL
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 Oracle9i: SQL
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 Oracle9i: SQL
Types of Functions Oracle9i: SQL
Case Conversion Functions Alter the case of data stored in a column or character string Oracle9i: SQL
LOWER Function Used to convert characters to lower-case letters Oracle9i: SQL
UPPER Function Used to convert characters to upper-case letters Oracle9i: SQL
INITCAP Function Used to convert characters to mixed-case Oracle9i: SQL
Character Manipulation Functions Manipulates data by extracting substrings, counting number of characters, replacing strings, etc. Oracle9i: SQL
SUBSTR Function Used to return a substring, or portion of a string Oracle9i: SQL
LENGTHFunction Used to determine the number of characters in a string Oracle9i: SQL
LPADandRPADFunctions Used to pad, or fill in, a character string to a fixed width Oracle9i: SQL
LTRIMandRTRIMFunctions Used to remove a specific string of characters Oracle9i: SQL
REPLACEFunction Substitutes a string with another specified string Oracle9i: SQL
CONCATFunction Used to concatenate two character strings Oracle9i: SQL
Number Functions Allows for manipulation of numeric data Oracle9i: SQL
ROUNDFunction Used to round numeric columns to a stated precision Oracle9i: SQL
TRUNCFunction Used to truncate a numeric value to a specific position Oracle9i: SQL
Date Functions Used to perform date calculations or format date values Oracle9i: SQL
MONTHS_BETWEENFunction Determines the number of months between two dates Oracle9i: SQL
ADD_MONTHSFunction Adds a specified number of months to a date Oracle9i: SQL
NEXT_DAYFunction Determines the next occurrence of a specified day of the week after a given date Oracle9i: SQL
TO_DATEFunction Converts various date formats to the internal format (DD-MON-YYYY) used by Oracle9i Oracle9i: SQL
FormatModelElements - Dates Oracle9i: SQL
NVL Function Substitutes a value for a NULL value Oracle9i: SQL
NVL2 Function Allows different actions based on whether a value is NULL Oracle9i: SQL
TO_CHAR Function Converts dates and numbers to a formatted character string Oracle9i: SQL
FormatModelElements – TimeandNumber Oracle9i: SQL
Other Functions • NVL • NVL2 • TO_CHAR • DECODE • SOUNDEX Oracle9i: SQL
DECODEFunction Determines action based upon values in a list Oracle9i: SQL
SOUNDEXFunction References phonetic representation of words Oracle9i: SQL
NestingFunctions • 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 Oracle9i: SQL
DUALTable • Dummy table • Consists of one column and one row • Can be used for table reference in the FROM clause Oracle9i: SQL