Chapter 5: Function

Function is the predefined block of code that accepts one or more arguments listed inside the parentheses, and then returns value as output.

Single-Row Function

Single-row function returns one row of results for each record processed.

Type of Function

Functins

Case Conversion Functions

UPPER, LOWER, INITCAP

Character Manipulation Functions

SUBSTR, INSTR, LENGTH, LPAD , RPAD, LTRIM, RTRIM, REPLACE, TRANSLATE, CONCAT

Numeric Functions

ROUND, TRUNC, MOD, ABS, POWER

Date Functions

MONTHS_BETWEEN, ADD_MONTHS, NEXT_DAY, LAST_DAY, TO_DATE, ROUND, TRUNC, CURRENT_DATE

Other Functions

NVL, NVL2, NULLIF, TO_CHAR, DECODE, CASE expression, SOUNDEX, TO_NUMBER

Case Conversion Functions

-- LOWER
-- Convert characters into lowercase letters.
SELECT LOWER(firstname), LOWER(lastname)
          FROM customers

-- UPPER
-- Convert characters into uppercase letters.
SELECT firstname, lastname
         FROM customers
         FROM lastname = UPPER('NELSON')

-- INITCAP
-- Convert the first letter of each word in the character string to uppercase and remaining characters into lowercase
SELECT INITCAP(fristname) AS "First Name", INITCAP(lastname) AS "Last Name"
       FROM customers

Character Manipulation Functions

Numeric Functions

Date Functions

By default, Oracle 12C displays data value in a DD-MON-YY format: 02-FEB-09.

Although user references a date value as a nonnumeric field, it is actually stored in a numeric format that includes century, year, month, day, hours, minutes and seconds.

The valid range is from January 1, 4712 B.C. to December 31 9999 A.D.

Other Function

Group-Rows Function

Also called Multiple-Rows Function, returns a result per group of rows processed.

All Group-Rows Function, except COUNT(*), ignore NULL values. If you want to include NULL values, please nest the NVL inside the Group-Rows Function.

Last updated

Was this helpful?