Lesson 1
Manipulating Data using Functions in Oracle
When using data from the database, you may find that you want to manipulate the data to fit your needs. For example, you may want to combine the city, state, and zip code together when printing out a mailing label. This module covers several built-in SQL functions that you have seen before but that have a slightly different syntax when done in Oracle.
This module also covers functions that are exclusive Oracle extensions to SQL.
Module Objectives
By the end of this module, you will be able to:
- List character (string) functions unique to Oracle or different in Oracle
- Interpret the effect of number functions
- Identify valid date-related date functions and Oracle's standard date format
- Identify valid time-related date/time functions
- Use
DECODE
and NVL
to modify query results
The module looks at functions by focusing on functions for character fields, for number fields, and for date/time fields.
The next several lessons discuss some functions that operate on character strings.
Oracle Functions manipulate data and return a result. In addition to an alphabetical listing of all functions, this chapter contains an overview of functions including:
- Numeric functions
- Character functions returning character values
- Character functions returning number values
- String functions
- LOB functions
- NLS character set functions
- General comparison functions
- Null-related comparison functions
- Conversion functions
- Datetime functions
- Aggregate functions
- Analytic functions
- Encoding function
- User and session functions
- Cache grid functions
Numeric Functions
Numeric functions accept numeric input and return numeric values. The numeric functions are:
- ABS
- CEIL
- FLOOR
- MOD
- POWER
- ROUND (expression)
- SIGN
- SQRT
- TRUNC (expression)
Character functions returning character values
The character functions that return character values are:
- CHR
- CONCAT
- LOWER and UPPER
- LPAD
- LTRIM
- NCHR
- NLSSORT
- REPLACE
- RPAD
- RTRIM
- SOUNDEX
- SUBSTR, SUBSTRB, SUBSTR4
- TRIM
Character Functions returning number values
Character functions that return number values are:
- ASCIISTR
- INSTR, INSTRB, INSTR4
- LENGTH, LENGTHB, LENGTH4
String functions
TimesTen supports these string functions in SELECT statements:
- INSTR, INSTRB, INSTR4
- LENGTH, LENGTHB, LENGTH4
- SUBSTR, SUBSTRB, SUBSTR4
A selected value that specifies a string function causes the SELECT result to be materialized. This causes overhead in both time and space.
A function is a built-in PL/SQL program that always returns a single value. You can use the predefined functions or you can create your own. A function always returns a single value, as opposed to a procedure, which is a similar type of program but is able to return more than one value. You can call a function within a query or other SQL command. Use the NVL function to convert null values before comparing them.