class orc book

174
Oracle 11g: SQL

Upload: dsunte-wilson

Post on 25-Sep-2015

53 views

Category:

Documents


4 download

DESCRIPTION

Oracle SQL

TRANSCRIPT

  • Oracle 11g: SQL

  • Module 1Overview of Database Concepts

    Oracle 11g: SQL

  • Oracle 11g: SQL 3

    Objectives

    Define database terms Identify the purpose of a database management

    system (DBMS) Explain database design using entity-relationship

    models and normalization Explain the purpose of a Structured Query

    Language (SQL) Understand how this textbooks topics are

    sequenced and how the two sample databases are used

  • Oracle 11g: SQL 4

    Database Terminology

    Database logical structure to store data

    Database management system (DBMS) software used to create and interact with the database

  • Oracle 11g: SQL 5

    Database Components

    Character Field Record File

  • Oracle 11g: SQL 6

    Database Components -Character

    Basic unit of data Can be a letter, number, or special symbol

  • Oracle 11g: SQL 7

    Database Components - Field

    A group of related characters Represents an attribute or characteristic of

    an entity

    Corresponds to a column in the physical database

  • Oracle 11g: SQL 8

    Database Components - Record

    A collection of fields for one specific entity Corresponds to a row in the physical

    database

  • Oracle 11g: SQL 9

    Database Components - File

    A group of records about the same type of entity

  • Oracle 11g: SQL 10

    Components Example

  • Oracle 11g: SQL 11

    Database Example

  • Oracle 11g: SQL 12

    Database Management System

    Data storage: manage the physical structure of the database

    Security: control user access and privileges Multiuser access: manage concurrent data access Backup: enable recovery options for database failures Data access language: provide a language that allows

    database access Data integrity: enable constraints or checks on data Data dictionary: maintain information about database

    structure

  • Oracle 11g: SQL 13

    Database Design

    Systems Development Life Cycle (SDLC) Entity-Relationship Model (E-R Model) Normalization

  • Oracle 11g: SQL 14

    Systems Development Life Cycle (SDLC)

    Systems investigation understanding the problem

    Systems analysis understanding the solution

    Systems design creating the logical and physical components

  • Oracle 11g: SQL 15

    Systems Development Life Cycle (SDLC) (continued)

    Systems implementation placing completed system into operation

    Systems maintenance and review evaluating the implemented system

  • Oracle 11g: SQL 16

    Entity-Relationship Model (E-R Model)

    Used to depict the relationship that exists among entities

    Model symbols:

  • Oracle 11g: SQL 17

    Relationships

    The following relationships can be included in an E-R Model: One-to-one

    One-to-many

    Many-to-many

  • Oracle 11g: SQL 18

    E-R Model Notation Examples

  • Oracle 11g: SQL 19

    One-to-one Relationship

    Each occurrence of data in one entity is represented by only one occurrence of data in the other entity

    Example: Each individual has just one Social Security Number (SSN) and each SSN is assigned to just one person

  • Oracle 11g: SQL 20

    One-to-many Relationship

    Each occurrence of data in one entity can be represented by many occurrences of the data in the other entity

    Example: A class has only one instructor, but each instructor can teach many classes

  • Oracle 11g: SQL 21

    Many-to-many Relationship

    Data can have multiple occurrences in both entities

    Example: A student can take many classes and each class is composed of many students

    Can not be included in the physical database

  • Oracle 11g: SQL 22

    Example E-R Model

  • Oracle 11g: SQL 23

    Database Normalization

    Determines required tables and columns for each table

    Multi-step process Used to reduce or control data redundancy

  • Oracle 11g: SQL 24

    Database Normalization (continued)

    Data redundancy - Refers to having the same data in different places within a database

    Data anomalies - Refers to data inconsistencies

  • Oracle 11g: SQL 25

    Unnormalized Data

    Contains repeating groups in the Author column in the BOOKS table

  • Oracle 11g: SQL 26

    First-Normal Form (1NF)

    Primary key is identified Repeating groups are eliminated

  • Oracle 11g: SQL 27

    First-Normal Form (1NF) (continued)

    ISBN and Author columns together create a composite primary key

  • Oracle 11g: SQL 28

    Composite Primary Key

    More than one column is required to uniquely identify a row

    Can lead to partial dependency - a column is only dependent on a portion of the primary key

  • Oracle 11g: SQL 29

    Second-Normal Form (2NF)

    Partial dependency must be eliminated Break the composite primary key into

    two parts, each part representing a separate table

  • Oracle 11g: SQL 30

    Second-Normal Form (2NF) (continued)

    BOOKS table in 2NF

  • Oracle 11g: SQL 31

    Third-Normal Form (3NF)

    Publisher contact name has been removed

  • Oracle 11g: SQL 32

    Summary of Normalization Steps

    1NF: eliminate repeating groups, identify the primary key

    2NF: table is in 1NF and partial dependencies are eliminated

    3NF: table is in 2NF and transitive dependencies are eliminated

  • Oracle 11g: SQL 33

    Relating Tables within the Database

    Once tables are normalized, make certain tables are linked

    Tables are linked through a common field A common field is usually a primary key in

    one table and a foreign key in the other table

  • Oracle 11g: SQL 34

  • Oracle 11g: SQL 35

    Structured Query Language (SQL)

    Data sublanguage Used to:

    Create or modify tables

    Add data to tables

    Edit data in tables

    Retrieve data from tables

    ANSI and ISO standards

  • Oracle 11g: SQL 36

    Databases used in this Textbook-JustLee Books Database

    Assumptions: No back orders or partial shipments

    Only US addresses

    Shipped orders are purged (deleted) at the end of the month

  • Oracle 11g: SQL 37

    Topic Sequence

    The first half of the text will focus on creating a database

    The second half of the text will focus on querying or retrieving data from a database

  • Oracle 11g: SQL 38

    Summary

    A DBMS is used to create and maintain a database A database is composed of a group of interrelated

    tables

    A file is a group of related records; a file is also called a table in the physical database

    A record is a group of related fields regarding one specific entity; a record is also called a row

  • Oracle 11g: SQL 39

    Summary (continued)

    A record is considered unnormalized if it contains repeating groups

    A record is in first-normal form (1NF) if no repeating groups exist and it has a primary key

    Second-normal form (2NF) is achieved if the record is in 1NF and has no partial dependencies

    After a record is in 2NF and all transitive dependencies have been removed, then it is in third-normal form (3NF), which is generally sufficient for most databases

  • Oracle 11g: SQL 40

    Summary (continued)

    A primary key is used to uniquely identify each record

    A common field is used to join data contained in different tables

    A foreign key is a common field that exists between two tables but is also a primary key in one of the tables

    A Structured Query Language (SQL) is a data sublanguage that navigates the data stored within a databases tables

  • Module 2Basic SQL SELECT Statements

    Oracle 11g: SQL

  • 42 Oracle 11g: SQL

    Objectives

    Distinguish between an RDBMS and an ORDBMS

    Identify keywords, mandatory clauses, and optional clauses in a SELECT statement

    Select and view all columns of a table Select and view one column of a table Display multiple columns of a table

  • 43 Oracle 11g: SQL

    Objectives (continued)

    Use a column alias to clarify the contents of a particular column

    Perform basic arithmetic operations in the SELECT clause

    Remove duplicate lists using either the DISTINCT or UNIQUE keyword

    Use concatenation to combine fields, literals, and other data

    Insert a line break

  • 44 Oracle 11g: SQL

    Relational Database Management System (RDBMS)

    An RDBMS is the software program used to create the database and it allows you to enter, manipulate, and retrieve data

  • 45 Oracle 11g: SQL

    Object Relational Database Management System (ORDBMS) Same as an RDBMS except it can be used

    to reference objects such as maps and object fields

  • 46 Oracle 11g: SQL

    Create the JustLee Database

    Use the provided script to create the database so you can follow the module examples

    Verify table contents using the DESCRIBE command

  • 47 Oracle 11g: SQL

    SELECT Statement Syntax

    SELECT statements are used to retrieve data from the database

    Syntax gives the basic structure, or rules, for a command

  • 48 Oracle 11g: SQL

    SELECT Statement Syntax (continued)

    Optional clauses and keywords are shown in brackets

  • 49 Oracle 11g: SQL

    SELECT Statement Syntax (continued)

    SELECT and FROM clauses are required SELECT clause identifies column(s) FROM clause identifies table(s) Each clause begins with a keyword

  • 50 Oracle 11g: SQL

    Selecting All Data in a Table

    Substitute an asterisk for the column names in a SELECT clause

  • 51 Oracle 11g: SQL

    Selecting One Column from a Table

    Enter column name in SELECT clause

  • 52 Oracle 11g: SQL

    Selecting Multiple Columns from a Table

    Separate column names with a comma

  • 53 Oracle 11g: SQL

    Operations Within the SELECT Statement

    Column alias can be used for column headings

    Perform arithmetic operations Suppress duplicates Concatenate data

  • 54 Oracle 11g: SQL

    Using Column Aliases

    List the alias after the column heading AS keyword is optional Enclose in double quotation marks:

    If it contains blank space(s)

    If it contains special symbol(s)

    To retain case

  • 55 Oracle 11g: SQL

    Column Alias Example

  • 56 Oracle 11g: SQL

    Using Arithmetic Operations

    Arithmetic operations: Executed left to right

    Multiplication and division are solved first

    Addition and subtraction are solved last

    Override order with parentheses

  • 57 Oracle 11g: SQL

    Example Arithmetic Operation with Column Alias

  • 58 Oracle 11g: SQL

    Using DISTINCT and UNIQUE Enter DISTINCT or UNIQUE after SELECT keyword to

    suppress duplicates

  • 59 Oracle 11g: SQL

    Using Concatenation

    You can combine data with a string literal Use the concatenation operator, || It allows the use of column aliases

  • 60 Oracle 11g: SQL

    Concatenation Example

    Note: incomplete results shown

  • 61 Oracle 11g: SQL

    Inserting a Line Break

    A line break code of CHR(10) can be used to format output on multiple lines

    The output must be formatted as text output in SQL*Plus for the line break command to operate properly

  • 62 Oracle 11g: SQL

    Summary

    Oracle 11g is an ORDBMS A basic query in Oracle 11g SQL includes the SELECT

    and FROM clauses, the only mandatory clauses in a SELECT statement

    To view all columns in the table, specify an asterisk (*) or list all the column names individually in the SELECT clause

    To display a specific column or set of columns, list the column names in the SELECT clause (in the order in which you want them to appear)

    When listing column names in the SELECT clause, a comma must separate column names

  • 63 Oracle 11g: SQL

    Summary (continued)

    A column alias can be used to clarify the contents of a particular column; if the alias contains spaces or special symbols, or if you want to display the column with any lowercase letters, you must enclose the column alias in double quotation marks (" ")

    Basic arithmetic operations can be performed in the SELECT clause

    To remove duplicate listings, include either the DISTINCT or UNIQUE keyword

    To specify which table contains the desired columns, you must list the name of the table after the keyword FROM

  • 64 Oracle 11g: SQL

    Summary (continued)

    Use vertical bars (||) to combine, or concatenate, fields, literals, and other data

    A line break code of CHR(10) can be used to format output on multiple lines; the output must be formatted as text output in SQL*Plus for the line break command to operate properly

  • Module 3Restricting Rows and Sorting

    Data

    Oracle 11g: SQL

  • Oracle 11g: SQL 66

    Objectives

    Use a WHERE clause to restrict the rows returned by a query

    Create a search condition using mathematical comparison operators

    Use the BETWEENAND comparison operator to identify records within a range of values

    Specify a list of values for a search condition using the IN comparison operator

  • Oracle 11g: SQL 67

    Objectives (continued)

    Search for patterns using the LIKE comparison operator

    Identify the purpose of the % and _ wildcard characters

    Join multiple search conditions using the appropriate logical operator

    Perform searches for NULL values Specify the order for the presentation of query

    results using an ORDER BY clause

  • Oracle 11g: SQL 68

    WHERE Clause Syntax

    A WHERE clause is used to retrieve rows based on a stated condition

    Requires: Column name

    Comparison operator

    Value or column for comparison

    Values are case sensitive

  • Oracle 11g: SQL 69

    WHERE Clause Example

    List WHERE clause after FROM clause Enclose nonnumeric data in single quotes

  • Oracle 11g: SQL 70

    Comparison Operators

    Indicate how the data should relate to the given search value

  • Oracle 11g: SQL 71

    Arithmetic Comparison Operators

  • Oracle 11g: SQL 72

    Other Comparison Operators

  • Oracle 11g: SQL 73

    BETWEENAND Operator

    Finds values in a specified range

  • Oracle 11g: SQL 74

    IN Operator

    Returns records that match a value in a specified list

    List must be in parentheses Values are separated by commas

  • Oracle 11g: SQL 75

    IN Operator Example

  • Oracle 11g: SQL 76

    LIKE Operator

    Performs pattern searches Used with wildcard characters:

    Underscore (_) for exactly one character in the indicated position

    Percent sign (%) represents any number of characters

  • Oracle 11g: SQL 77

    LIKE Operator Example

  • Oracle 11g: SQL 78

    Logical Operators

    Used to combine conditions Evaluated in order of NOT, AND, OR:

    NOT reverses meaning

    AND both conditions must be TRUE

    OR at least one condition must be TRUE

  • Oracle 11g: SQL 79

    AND Logical Operator Example

  • Oracle 11g: SQL 80

    OR Logical Operator Example

  • Oracle 11g: SQL 81

    Multiple Logical Operators

    Resolved in order of NOT, AND, OR

  • Oracle 11g: SQL 82

    Multiple Logical Operators

    Use parentheses to override the order of evaluation

  • Oracle 11g: SQL 83

    Resolving Multiple Types of Operators

    1. Arithmetic operators

    2. Comparison operators

    3. Logical operators

  • Oracle 11g: SQL 84

    Treatment of NULL Values

    Absence of data Requires use of IS NULL operator

  • Oracle 11g: SQL 85

    Treatment of NULL Values (continued)

    A common error is using = NULL which does not raise an Oracle error but it also does not return any rows

  • Oracle 11g: SQL 86

    ORDER BY Clause Syntax

    The ORDER BY clause presents data in sorted order

    Ascending order is default Use DESC keyword to override column

    default

    255 columns maximum

  • Oracle 11g: SQL 87

    ORDER BY Clause Syntax Sort Sequence

    In ascending order, values will be listed in the following sequence: Numeric values

    Character values

    NULL values

    In descending order, sequence is reversed

  • Oracle 11g: SQL 88

    ORDER BY Example

  • Oracle 11g: SQL 89

    ORDER BY Can Reference Column Position

  • Oracle 11g: SQL 90

    Summary

    The WHERE clause can be included in a SELECT statement to restrict the rows returned by a query to only those meeting a specified condition

    When searching a nonnumeric field, the search values must be enclosed in single quotation marks

    Comparison operators are used to indicate how the record should relate to the search value

    The BETWEEN...AND comparison operator is used to search for records that fall within a certain range of values

  • Oracle 11g: SQL 91

    Summary (continued)

    The LIKE comparison operator is used with the percent and underscore symbols (% and_) to establish search patterns

    Logical operators such as AND and OR can be used to combine several search conditions

    When using the AND operator, all conditions must be TRUE for a record to be returned in the results However, with the OR operator, only one condition must be TRUE

    A NULL value is the absence of data, not a field with a blank space entered

  • Oracle 11g: SQL 92

    Summary (continued)

    Use the IS NULL comparison operator to match NULL values; the IS NOT NULL comparison operator finds records that do not contain NULL values in the indicated column

    You can sort the results of queries by using an ORDER BY clause; when used, the ORDER BY clause should be listed last in the SELECT statement

    By default, records are sorted in ascending order; entering DESC directly after the column name sorts the records in descending order

    A column does not have to be listed in the SELECT clause to serve as a basis for sorting

  • Module 4Joining Data from

    Multiple Tables

    Oracle 11g: SQL

  • Oracle 11g: SQL 94

    Objectives

    Identify a Cartesian join Create an equality join using the WHERE clause Create an equality join using the JOIN keyword Create a non-equality join using the WHERE

    clause

    Create a non-equality join using the JOINON approach

  • Oracle 11g: SQL 95

    Objectives (continued)

    Create a self-join using the WHERE clause Create a self-join using the JOIN keyword Distinguish an inner join from an outer join Create an outer join using the WHERE clause Create an outer join using the OUTER

    keyword Use set operators to combine the results of

    multiple queries

  • Oracle 11g: SQL 96

    Purpose of Joins

    Joins are used to link tables and reconstruct data in a relational database

    Joins can be created through: Conditions in a WHERE clause

    Use of JOIN keywords in FROM clause

  • Oracle 11g: SQL 97

    Cartesian Joins

    Created by omitting joining condition in the WHERE clause or through CROSS JOIN keywords in the FROM clause

    Results in every possible row combination (m * n)

  • Oracle 11g: SQL 98

    Cartesian Join Example:Omitted Condition

  • Oracle 11g: SQL 99

    Cartesian Join Example:CROSS JOIN Keywords

  • Oracle 11g: SQL 100

    Equality Joins

    Link rows through equivalent data that exists in both tables

    Created by: Creating equivalency condition in the WHERE

    clause

    Using NATURAL JOIN, JOINUSING, or JOINON keywords in the FROM clause

  • Oracle 11g: SQL 101

    Equality Joins: WHERE Clause Example

  • Oracle 11g: SQL 102

    Qualifying Column Names

    Columns in both tables must be qualified

  • Oracle 11g: SQL 103

    WHERE Clause Supports Join and Other Conditions

  • Oracle 11g: SQL 104

    Joining More Than Two Tables

    Joining 4 tables requires 3 join conditions

  • Oracle 11g: SQL 105

    Equality Joins: NATURAL JOIN

  • Oracle 11g: SQL 106

    No Qualifiers with a NATURAL JOIN

  • Oracle 11g: SQL 107

    Equality Joins: JOINUSING

  • Oracle 11g: SQL 108

    Equality Joins: JOINON

    Required if column names are different

  • Oracle 11g: SQL 109

    JOIN Keyword Overview

    Use JOINUSING when tables have one or more columns in common

    Use JOINON when same named columns are not involved or a condition is needed to specify a relationship other than equivalency (next section)

    Using the JOIN keyword frees the WHERE clause for exclusive use in restricting rows

  • Oracle 11g: SQL 110

    Non-Equality Joins

    In WHERE clause, use any comparison operator other than the equal sign

    In FROM clause, use JOINON keywords with a non-equivalent condition

  • Oracle 11g: SQL 111

    Non-Equality Joins: WHERE Clause Example

  • Oracle 11g: SQL 112

    Non-Equality Joins: JOINON Example

  • Oracle 11g: SQL 113

    Self-Joins

    Used to link a table to itself Requires the use of table aliases Requires the use of a column qualifier

  • Oracle 11g: SQL 114

    Customer Table Example

  • Oracle 11g: SQL 115

    Self-Joins: WHERE Clause Example

  • Oracle 11g: SQL 116

    Self-Joins: JOINON Example

  • Oracle 11g: SQL 117

    Outer Joins

    Use outer joins to include rows that do not have a match in the other table

    In WHERE clause, include outer join operator (+) immediately after the column name of the table with missing rows to add NULL rows

    In FROM clause, use FULL, LEFT, or RIGHT with OUTER JOIN keywords

  • Oracle 11g: SQL 118

    Outer Joins: WHERE Clause Example

  • Oracle 11g: SQL 119

    Outer Joins: OUTER JOIN Keyword Example

  • Oracle 11g: SQL 120

    Outer Joins (continued)

    If multiple join conditions are used, the outer join condition may be required in all the join conditions to retain non-matching rows

  • Oracle 11g: SQL 121

    Set Operators

    Used to combine the results of two or more SELECT statements

  • Oracle 11g: SQL 122

    Set Operators: UNION Example

  • Oracle 11g: SQL 123

    Set Operators: INTERSECT Example

  • Oracle 11g: SQL 124

    Set Operators: MINUS Example

  • Oracle 11g: SQL 125

    Summary

    Data stored in multiple tables regarding a single entity can be linked together through the use of joins

    A Cartesian join between two tables returns every possible combination of rows from the tables; the resulting number of rows is always m * n

    An equality join is created when the data joining the records from two different tables are an exact match

    A non-equality join establishes a relationship based upon anything other than an equal condition

    Self-joins are used when a table must be joined to itself to retrieve needed data

  • Oracle 11g: SQL 126

    Summary (continued)

    Inner joins are categorized as being equality, non-equality, or self-joins

    An outer join is created when records need to be included in the results without having corresponding records in the join tables The record is matched with a NULL record so it will be

    included in the output

    Set operators such as UNION, UNION ALL, INTERSECT, and MINUS can be used to combine the results of multiple queries

  • Module 5Selected Single-Row Functions

    Oracle 11g: SQL

  • Oracle 11g: SQL 128

    Objectives

    Use the UPPER, LOWER, and INITCAP functions to change the case of field values and character strings

    Extract a substring using the SUBSTR function Locate a substring within a character string with the INSTR

    function

    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

  • Oracle 11g: SQL 129

    Objectives (continued)

    Use the LTRIM and RTRIM functions to remove specific characters strings

    Substitute character string values with the REPLACE and TRANSLATE functions

    Round and truncate numeric data using the ROUND and TRUNC functions

    Return the remainder only of a division operation using the MOD function

    Calculate the number of months between two dates using the MONTHS_BETWEEN function

    Manipulate date data using the ADD_MONTHS, NEXT_DAY, TO_DATE, and ROUND functions

  • Oracle 11g: SQL 130

    Objectives (continued)

    Extend pattern matching capabilities with regular expressions

    Identify and correct problems associated with calculations involving NULL values using the NVL function

    Display dates and numbers in a specific format with the TO_CHAR function

    Perform condition processing similar to an IF statement with the DECODE function

    Use the SOUNDEX function to identify character phonetics Use the DUAL table to test functions

  • Oracle 11g: SQL 131

    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 module)

  • Oracle 11g: SQL 132

    Types of Functions

  • Oracle 11g: SQL 133

    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

  • Oracle 11g: SQL 134

    LOWER Function

    Used to convert characters to lowercase letters

  • Oracle 11g: SQL 135

    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

  • Oracle 11g: SQL 136

    INITCAP Function

    Used to convert characters to mixed case

  • Oracle 11g: SQL 137

    Character Manipulation Functions

    Character manipulation functions manipulate data by extracting substrings, counting the number of characters, replacing strings, etc.

  • Oracle 11g: SQL 138

    SUBSTR Function

    Used to return a substring, or portion of a string

  • Oracle 11g: SQL 139

    INSTR Function

  • Oracle 11g: SQL 140

    Nesting Functions

  • Oracle 11g: SQL 141

    LENGTH Function

    Used to determine the number of characters in a string

  • Oracle 11g: SQL 142

    LPAD and RPAD Functions

    Used to pad, or fill in, a character string to a fixed width

  • Oracle 11g: SQL 143

    LTRIM and RTRIM Functions

    Used to remove a specific string of characters

  • Oracle 11g: SQL 144

    REPLACE Function

    Substitutes a string with another specified string

  • Oracle 11g: SQL 145

    TRANSLATE Function

  • Oracle 11g: SQL 146

    CONCAT Function

    Used to concatenate two character strings

  • Oracle 11g: SQL 147

    Number Functions

    Allow for manipulation of numeric data: ROUND

    TRUNC

    MOD

    ABS

  • Oracle 11g: SQL 148

    ROUND Function

    Used to round numeric columns to a stated precision

  • Oracle 11g: SQL 149

    TRUNC Function

    Used to truncate a numeric value to a specific position

  • Oracle 11g: SQL 150

    MOD Function

  • Oracle 11g: SQL 151

    ABS Function

  • Oracle 11g: SQL 152

    Date Functions

    Used to perform date calculations or format date values Subtract date for number of days difference

  • Oracle 11g: SQL 153

    MONTHS_BETWEEN Function

    Determines the number of months between two dates

  • Oracle 11g: SQL 154

    ADD_MONTHS Function

    Adds a specified number of months to a date

  • Oracle 11g: SQL 155

    NEXT_DAY Function

    Determines the next occurrence of a specified day of the week after a given date

  • Oracle 11g: SQL 156

    TO_DATE Function

    Converts various date formats to the internal format (DD-MON-YY) used by Oracle 11g

  • Oracle 11g: SQL 157

    Format Model Elements - Dates

  • Oracle 11g: SQL 158

    ROUND Function

  • Oracle 11g: SQL 159

    TRUNC Function

  • Oracle 11g: SQL 160

    Regular Expressions

    Regular expressions allow the description of complex patterns in textual data

  • Oracle 11g: SQL 161

    REGEXP_LIKE

  • Oracle 11g: SQL 162

    Other Functions

    NVL NVL2 TO_CHAR DECODE SOUNDEX

  • Oracle 11g: SQL 163

    NVL Function

    Substitutes a value for a NULL value

  • Oracle 11g: SQL 164

    NVL2 Function

    Allows different actions based on whether a value is NULL

  • Oracle 11g: SQL 165

    TO_CHAR Function

    Converts dates and numbers to a formatted character string

  • Oracle 11g: SQL 166

    Format Model Elements Time and Number

  • Oracle 11g: SQL 167

    DECODE Function

    Determines action based upon values in a list

  • Oracle 11g: SQL 168

    SOUNDEX Function

    References phonetic representation of words

  • Oracle 11g: SQL 169

    TO_NUMBER Function

  • Oracle 11g: SQL 170

    DUAL Table

    Dummy table Consists of one column and one row Can be used for table reference in the FROM

    clause

  • Oracle 11g: SQL 171

    Using DUAL

  • Oracle 11g: SQL 172

    Summary

    Single-row functions return a result for each row or record processed

    Character case conversion functions such as UPPER, LOWER, and INITCAP can be used to alter the case of character strings

    Nesting one function within another allows multiple operations to be performed on data

    Simple number functions such as ROUND and TRUNC can round or truncate a number on both the left and right side of a decimal

  • Oracle 11g: SQL 173

    Summary (continued)

    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 and NVL2 functions are used to address problems encountered with NULL values

  • Oracle 11g: SQL 174

    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 SOUNDEX function looks for records based on the phonetic representation of characters

    The DUAL table can be helpful when testing functions