oracle sql

9
Oracle SQL Character Functions

Upload: iniko

Post on 04-Jan-2016

38 views

Category:

Documents


1 download

DESCRIPTION

Oracle SQL. Character Functions. Overview. A Function is a type of formula whose result is one of two things: A transformation Such as changing a student’s name to upper case letters Information Such as finding the length of a word in a column - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Oracle SQL

Oracle SQL Character Functions

Page 2: Oracle SQL

Overview

A Function is a type of formula whose result is one of two things:

A transformation

Such as changing a student’s name to upper case letters

Information

Such as finding the length of a word in a column

Functions are named and usually require at least one parameter

All functions in this section perform the transformation/information on a single row of the table

Aggregate functions perform against multiple rows

Page 3: Oracle SQL

Data Types

Each value in a table row has a data type associated with it

A data type determines the value’s attributes and acceptable values

123 is a number data type

“abc” is a text data type

“abc” is NOT a number data type

Most SQL operations use the following data types:

NUMBER

VARCHAR2

DATE

Page 4: Oracle SQL

Reading Function Syntax Diagrams

[ ] Square brackets enclose syntax options

{ } Braces enclose items of which only one is required

| A vertical bar denotes options

… Three dots indicate that the preceding expression can be repeated

Delimiters

Example of delimiters are commas and parentheses, etc.

CAPS Indicate Oracle keywords

UNDERLINE

Indicates a default value

Syntax Symbols

Page 5: Oracle SQL

Character Functions

LOWER(string1) Converts to lowercase

UPPER(string1) Converts to uppercase

INITCAP(string1) Capitalizes the first letter

LPAD( string1, padded_length, [ pad_string ] )

Left pads

RPAD( string1, padded_length, [ pad_string ] )

Right pads

LTRIM( string1, [ trim_string ] ) Left trims

RTRIM( string1, [ trim_string ] ) Right trims

Character Functions

Page 6: Oracle SQL

Character Functions

TRIM([LEADING|TRAILING|BOTH] trim_character FROM string1)

Trims leading, trailing or both sides

SUBSTR( string1, start_position, [ length ] ) Cuts out a piece of a string

INSTR( string1, string2 [, start_position [, nth_appearance ] ] )

Determines the starting location of a string

Character Functions continued

Page 7: Oracle SQL

Character Functions

LENGTH(string1) Returns the length of a string

CONCAT(string1,string2) Concatenates two strings

REPLACE( string1, string_to_replace, [ replacement_string ] )

Replaces a string with another string

SOUNDEX(string1) Returns phonetic representation

TRANSLATE( string1, string_to_replace, replacement_string )

Substitutes individual characters

Character Functions continued

Page 8: Oracle SQL

Character Functions Practice

Write a query to show the city within the zipcode table as all capital letters, all lower case letters and mixed case letters

Use one query to show all three variations

Write a query to return the first 3 letters of a student’s last name from the student table

Write a query to display the length of each student’s last name

Using the CONCAT function, concatenate cities and states together (zipcode table)

Now use ||’s to add a comma and space

New York, NY

Using SOUNDEX list all last names that sound like ‘MARTIN’ (student table)

Hint: use a Where soundex (last_name) = soundex (‘MARTIN’) clause

Page 9: Oracle SQL

For March 10th

Number Functions

Quiz

Project 10 is due