Using Single Row Functions
Using Single Row Functions
Single Row functions - Single row functions are the one who work on single row and return one
output per row. For example, length and case conversion functions are single row functions.
Multiple Row functions - Multiple row functions work upon group of rows and return one result
for the complete set of rows. They are also known as Group Functions.
General functions - Usually contains NULL handling functions. The functions under the
category are NVL, NVL2, NULLIF, COALESCE, CASE, DECODE.
Case Conversion functions - Accepts character input and returns a character value.
Functions under the category are UPPER, LOWER and INITCAP.
INITCAP function converts only the initial alphabets of a string to upper case.
Character functions - Accepts character input and returns number or character value.
Functions under the category are CONCAT, LENGTH, SUBSTR, INSTR, LPAD, RPAD, TRIM and
REPLACE.
SUBSTR function returns a portion of a string from a given start point to an end point.
LPAD and RPAD functions pad the given string upto a specific length with a given
character.
TRIM function trims the string input from the start or end.
REPLACE function replaces characters from the input string with a given character.
Date functions - Date arithmetic operations return date or numeric values. Functions under
the category are MONTHS_BETWEEN, ADD_MONTHS, NEXT_DAY, LAST_DAY, ROUND and
TRUNC.
MONTHS_BETWEEN function returns the count of months between the two dates.
ADD_MONTHS function add 'n' number of months to an input date.
LAST_DAY function returns last day of the month of the input date.
ROUND and TRUNC functions are used to round and truncates the date value.
Number functions - Accepts numeric input and returns numeric values. Functions under
the category are ROUND, TRUNC, and MOD.
ROUND and TRUNC functions are used to round and truncate the number value.
MOD is used to return the remainder of the division operation between two numbers.
Illustrations
General functions
The SELECT query below demonstrates the use of NVL function.
Character functions
The SELECT query below demonstrates the use of CONCAT function to concatenate two string
values.
CONCAT(FIRST_NAME,LAST_NAME)
--------------------------------
EllenAbel
SundarAnde
MozheAtkinson
DavidAustin
The SELECT query below demonstrates the use of SUBSTR and INSTR functions. SUBSTR function
returns the portion of input string from 1st position to 5th position. INSTR function returns the
numeric position of character 'a' in the first name.
SUBST INSTR(FIRST_NAME,'A')
----- ---------------------
Ellen 0
Sunda 5
Mozhe 0
David 2
The SELECT query below demonstrates the usage of LPAD and RPAD to pretty print the employee
and job information.
RPAD(FIRST_NAME,10,'_')||
-------------------------
Steven____________AD_PRES
Neena_______________AD_VP
Lex_________________AD_VP
Alexander_________IT_PROG
Number functions
The SELECT query below demonstrates the use of ROUND and TRUNC functions.
ROUND(1372.472,1)
-----------------
1372.5
TRUNC(72183,-2)
---------------
72100
EMPLOYEE_ID EMPLOYMENT_DAYS
----------- ---------------
100 3698.61877
101 2871.61877
102 4583.61877
103 2767.61877
Date functions
The SELECT query below demonstrates the use of MONTHS_BETWEEN, ADD_MONTHS, NEXT_DAY
and LAST_DAY functions.
EMPLOYEE_ID EMPLOYMENT_MONTHS
----------- -----------------
100 121.504216
101 94.3751837
102 150.633248
103 90.9558289