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
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)
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
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
Character Manipulation Functions • Character manipulation functions manipulate data by extracting substrings, counting the number of characters, replacing strings, etc.
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
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
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