SQL 101 2nd Session.

Slides:



Advertisements
Similar presentations
Copyright  Oracle Corporation, All rights reserved. 2 Single-Row Functions.
Advertisements

Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
 A function is a type of formula whose result is one of two things: either a transformation or information.  Syntax Symbols SYMBOLUSAGE []Square brackets.
CS 3630 Database Design and Implementation. SQL Query Clause Select and From Select * From booking; select hotel_no, guest_no, room_no from booking; select.
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
10/28/1999Database Management -- R. Larson ORACLE SQLPlus Updating and Modifying Data In SQL University of California, Berkeley School of Information Management.
Introduction to Oracle9i: SQL1 Selected Single-Row Functions.
Using Single-Row Functions to Customize Output
Lecture 6 29/1/15. Number functions Number functions take numbers as input, change them, and output the results as numbers. 2.
SQL Use of Functions Character functions Please use speaker notes for additional information!
Ch. 3 Single-Row Functions Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
Single-Row Functions. SQL Functions Functions are a very powerful feature of SQL and can be used to do the following: Perform calculations on data Modify.
3-1 Copyright  Oracle Corporation, All rights reserved. SQL Functions FunctionInput arg 1 arg 2 arg n Function performs action OutputResultvalue.
Oracle FUNCTIONS. Comment ScreenShot (in 10g) General Example of null Foreign Key: create table deptcs( deptno NUMBER(4) primary key, hiredate DATE,
Number Functions. 2 home back first prev next last Review single-row character functions –character case-manipulation functions  LOWER, UPPER, INITCAP.
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
2-1 Copyright © Oracle Corporation, All rights reserved. Character Strings and Dates Character strings and date values are enclosed in single quotation.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Chapter 5 Selected Single-Row Functions. Chapter Objectives  Use the UPPER, LOWER, and INITCAP functions to change the case of field values and character.
Single-Row Functions. Two Types of SQL Functions There are two distinct types of functions: Single-row functions Multiple-row functions Single-Row Functions.
SINGLE-ROW FUNCTIONS Lecture 9. SQL Functions Functions are very powerful feature of SQL and can be used to do the following:  Perform a calculation.
Functions Oracle Labs 5 & 6. 2/3/2005Adapted from Introduction to Oracle: SQL and PL/SQL 2 SQL Functions Function arg n arg 2 arg 1. Input Resulting Value.
1 Data Manipulation in SQL  Department of Computer Science Northern Illinois University February 2001.
3 Copyright © 2004, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
Single – Row Functions. Objectives After completing this lesson, you should be able to do the following:  Describe various types of functions available.
Single Row Functions Week 2. Objectives –Describe types of single row functions in SQL –Describe and use character, number, date, general and conversion.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
SQL Oracle PL/SQL. Select SELECT column1, column2,...columnN FROM table_name WHERE condition; SELECT column1, column2,...columnN FROM table_name WHERE.
SINGLE ROW FUNCTIONS 1. CHARACTER MANIPULATION Prof. Carmen Popescu Oracle Academy Lead Adjunct.
Chapter 3 Selected Single-Row Functions and Advanced DML & DDL.
6 Copyright © 2006, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
2-1 Copyright © Oracle Corporation, All rights reserved. Using the NULL Conditions Test for nulls with the IS NULL operator. SELECT last_name, manager_id.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Single Row Functions. Objectives –Use character, number, and date functions –Use conversion functions –Describe types of single row functions in SQL.
1 Creating and Maintaining Database Objects Part 1 Database Systems.
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
3 第三讲 Single-Row Functions. Objectives After completing this lesson, you should be able to do the following: Describe various types of functions available.
6 Copyright © Oracle Corporation, All rights reserved. Subqueries.
SQL Functions. SQL functions are built into Oracle Database and are available for use in various appropriate SQL statements. These functions are use full.
1 Session 6: Database Best Practice iNET Academy Open Source Web Development.
Built-in SQL Functions. 2 Type of Functions Character Functions returning character values returning numeric values Numeric Functions Date Functions Conversion.
Using Single-Row Functions to Customize Output
3 Copyright © 2007, Oracle. All rights reserved. Substitution Variables ra Oly l&On nase lce Int erU.
4/2/16. Ltrim() is used to remove leading occurrences of characters. If we don’t specify a character, Oracle will remove leading spaces. For example Running.
1 Inside Module 8 Extracting Data Page n Using the Extract command2 n Coercion3 n $-functions4 n Extract from a table7.
[ ] Square brackets enclose syntax options { } Braces enclose items of which only one is required | A vertical bar denotes options … Three dots indicate.
Gollis University Faculty of Computer Engineering Chapter Five: Retrieval, Functions Instructor: Mukhtar M Ali “Hakaale” BCS.
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
Copyright  Oracle Corporation, All rights reserved. 3 Single-Row Functions.
Single Row Functions Part I Week 2. Objectives –Describe types of single row functions in SQL –Describe and use character, number and date SQL functions.
CS 3630 Database Design and Implementation
Open Source Server Side Scripting MySQL Functions
Using Single-Row Functions to Customize Output
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Restricting and Sorting Data
Using Single-Row Functions to Customize Output
Chapter Nine Data Manipulation Language (DML) Functions
SQL 101 3rd Session.
CS 3630 Database Design and Implementation
Computations Done on table data
Using Single-Row Functions to Customize Output
Oracle SQL Built-in Functions
CS122 Using Relational Databases and SQL
دوال حرفية دوال رقميه دوال تاريخ دوال تحويل
Single-Row Functions Lecture 9.
Index Note: A bolded number or letter refers to an entire lesson or appendix. A Adding Data Through a View ADD_MONTHS Function 03-22, 03-23,
Lecture 5 SQL FUNCTIONS.
Presentation transcript:

SQL 101 2nd Session

Functions: - Character functions  today - Number functions - Single Row functions

Character Functions: LOWER UPPER INITCAP LPAD RPAD LTRIM RTRIM TRIM SUBSTR INSTR LENGTH in WHERE & GROUP BY clauses Nested functions Concatenation REPLACE TRANSLATE SOUNDEX

Single-Row Functions: NVL COALESCE NVL2 LNNVL NULLIF NANVL DECODE Searched CASE Simple CASE

Number Functions: ABS SIGN ROUND TRUNC FLOOR CEIL MOD REMAINDER Floating point numbers Arithmetic operators

Character functions.... UPPER(char) LOWER(char) INITCAP(char) LPAD(char1, n [, char2]) RPAD(char1, n [, char2]) SELECT state, LOWER(state), LOWER('State') FROM zipcode; SELECT UPPER(city) as "Upper Case City", state, INITCAP(state) WHERE zip = '10035'; SELECT RPAD(city, 20, '*') as "City Name", LPAD(state, 10, '-') as "State Name"

A single row is always returned in the result set. Character functions.... The DUAL table Character functions.... The DUAL table contains a single row and a single column called DUMMY. It’s often used with functions to select values that do not exist in tables such as today’s date. A single row is always returned in the result set. This table is owned by SYS and is available to all users. SELECT * from dual;

SELECT TRIM(LEADING '0' FROM '0001234500') leading, Character functions.... LTRIM(char1 [, char2]) RTRIM(char1 [, char2]) TRIM([LEADING|TRAILING|BOTH] char1 FROM char2) TRIM(char2) SUBSTR(char1, start_pos [, substr_length]) SELECT LTRIM('0001234500', '0') left, RTRIM('0001234500', '0') right, LTRIM(RTRIM('0001234500', '0'), '0') both FROM dual; SELECT TRIM(LEADING '0' FROM '0001234500') leading, TRIM(TRAILING '0' FROM '0001234500') trailing, TRIM('0' FROM '0001234500') both Column "1-5" format a6 Column "6 only" format a6 SELECT last_name, SUBSTR(last_name, 1, 5) as "1-5", SUBSTR(last_name, 6) as "6 only" FROM student;

Column description format a30 Column "er" format 999 Character functions.... INSTR(char1, char2 [,start_pos [, occurrence]]) LENGTH(char1) Column description format a30 Column "er" format 999 SELECT description, INSTR(description, 'er') "er" FROM course; SELECT LENGTH('Hello there') FROM dual; SELECT first_name, last_name FROM student WHERE SUBSTR(last_name, 1, 2) = 'Mo';

WHERE and GROUP BY clauses: SELECT first_name, last_name FROM student WHERE INSTR(first_name, '.') > 0 ORDER BY LENGTH(last_name); Nested Functions: Column mi format a3 Column first format a10 SELECT first_name, SUBSTR(first_name, INSTR(first_name, '.') -1) mi, SUBSTR(first_name, 1, INSTR(first_name, '.') -2) first WHERE INSTR(first_name, '.') >= 3;

Concatenation: SELECT CONCAT(city, state) FROM zipcode; SELECT city||state||zip SELECT city||', '||state||' '||zip

SELECT REPLACE('My hand is asleep', 'hand', 'foot') FROM dual; Character functions.... REPLACE(char, if, then) TRANSLATE(char, if, then) SELECT REPLACE('My hand is asleep', 'hand', 'foot') FROM dual; SELECT REPLACE('My hand is asleep', 'X', 'foot') SELECT phone FROM student WHERE TRANSLATE(phone, '0123456789','##########') <> '###-###-####'; WHERE TRANSLATE(phone, '012345678','##########') <> '###-###-####';

Soundex: SELECT student_id, last_name FROM student WHERE SOUNDEX(last_name) = SOUNDEX('Torch'); Just my 2cents.... This function is crap.... Don't ever use BUT, know it exists.