Team Fly 

Page 51

    102238 CT                                                   15000
    101798 CT                                                   15000
    101515 CT                                                   15000
    103007 UT                                                   15000
     24830 UT                                                   15000
8 rows selected.

CRITICAL SKILL 2.6
Employ Functions: String, Numeric, Aggregate (No Grouping)

Up to now, we have illustrated a number of fairly simplistic DML statements. We've selected some records from different tables using criteria, we've updated existing rows, and we've even inserted and deleted some records.

Oracle provides us with many functions that allow us to analyze and aggregate the data, returning results that differ greatly from the result sets we've seen so far. A function manipulates the contents of a column in a SQL statement. We can find what the largest credit limit is in the CUSTOMERS table, we can round numbers or pad results with characters. In fact, when we ran a count of customers that were in the province of 'Delhi' before and after deleting these records, we took a sneak peek ahead at functions.

This section will introduce you to three different types of functions: string (or character), numeric, and aggregate.

String Functions

String functions, also known as character functions, can be categorized in two types: those that return character values and those that return numeric values.

Table 2-3 represents the most common functions you will perform with the character data type. It is only a partial list. The examples that follow all use the ''dual" table. The "dual" table is an internal Oracle table and is useful in SQL and PL/SQL to perform functions that return a single row. It can be used to return the current system date and time, to perform arithmetic functions or to obtain a generated sequential number (more on this later in the chapter).

Function

Action

Example

Displays

lower(char)

Converts the entire string to lowercase.

select lower('DAliA') from dual;

dalia

replace(char,str1,str2)

Replaces every occurrence of str1 in char with str2.

select replace('Scott', 'S', 'Boy') from dual;

Boycott

Team Fly 
0070-CRITICAL SKILL 2.6 Employ Functions: String, Numeric, Aggregate (No Grouping)