Single-Row Functions Lecture 9.

Slides:



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

Objectives After completing this lesson, you should be able to do the following: Describe various types of conversion functions that are available in.
Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Introduction to Oracle9i: SQL1 Selected Single-Row Functions.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Using Single-Row Functions to Customize Output
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.
3 Single-Row Functions. 3-2 Objectives At the end of this lesson, you should be able to: Describe various types of functions available in SQL Use character,
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.
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.
Copyright  Oracle Corporation, All rights reserved. 3 Single-Row Functions.
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.
Introduction to SQL PART Ⅰ 第一讲 Writing Basic SQL SELECT Statements.
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.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
Copyright  Oracle Corporation, All rights reserved. 3 Single-Row Functions.
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
Copyright س Oracle Corporation, All rights reserved. 3 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.
Introduction to Functions – Single Row Functions.
Using Single-Row Functions to Customize Output
3 Copyright © 2007, Oracle. All rights reserved. Substitution Variables ra Oly l&On nase lce Int erU.
Lab 3: Single-row Functions College of Information Technology, Universiti Tenaga Nasional 1 CISB224 02A, 02B Semester I, 2009/2010.
College of Information Technology, Universiti Tenaga Nasional1 Lab 2: Single-row Functions CISB224 01A CCSB244 01A Semester I, 2008/2009.
Writing Basic SQL SELECT Statements Lecture
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
1 Introduction to Database Systems, CS420 SQL JOIN, Group-by and Sub-query Clauses.
Defining a Column Alias
Single Row Functions. 3-2 Objectives Explain the various types of functions available in SQL. Explain the various types of functions available in SQL.
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.
Writing Basic SQL SELECT Statements
Single-Row Functions Schedule: Timing Topic 55 minutes Lecture
Using Single-Row Functions to Customize Output
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Single-Row Functions Schedule: Timing Topic 55 minutes Lecture
Basic select statement
Restricting and Sorting Data
Using Single-Row Functions to Customize Output
SQL 101 3rd Session.
Writing Basic SQL SELECT Statements
Computations Done on table data
Using Single-Row Functions to Customize Output
Restricting and Sorting Data
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
Using CASE Value expression
Lecture 5 SQL FUNCTIONS.
Lab 3: Single-row Functions
Restricting and Sorting Data
Presentation transcript:

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 on data Modify individual data items Manipulate output of groups of rows Format dates and numbers for display Convert column data types

Two Types of SQL Functions There are two distinct types of functions: Single-Row Functions These functions operate on single rows only and return one result per row. There are different types of single-row functions Multiple-Row Functions Functions can manipulate groups of rows to give one result per group of rows. These functions are known as group functions

Single-Row Functions Single row functions: Manipulate data items Accept arguments and return one value Act on each row returned Return one result per row May modify the data type Can be nested Can be used in SELECT, WHERE, and ORDER BY clauses Accept arguments which can be a column or an expression Syntax: function_name [(arg1, arg2,...)]

Single-Row Functions This lesson covers the following single -row functions: Character functions: accept character input and can return both character and number values Number functions: Accept numeric input and return numeric values

Character-manipulation Character Functions Character Functions Case-manipulation Character-manipulation LOWER UPPER INITCAP SUBSTR LENGTH

:Character Functions Case Manipulation Functions These functions convert case for character strings. See (Example 1, Example 2) Function result LOWER(‘SQL Course’) sql course UPPER(‘SQL Course’) SQL COURSE INITCAP(‘SQL Course’) Sql Course

:Character Functions Case Manipulation Functions

:Example1 SELECT 'The job id for '||UPPER(last_name)||' is ' ||LOWER(job_id) AS "EMPLOYEE DETAILS" FROM employees;

:Example2 Display the employee number, name, and department number for employee Higgins:

Character Functions: Character Manipulation Functions Purpose LENGTH(Column|expression) Returns the number of characters in the expression SUBSTR(column|expression,m [,n]) Returns specified characters from character value starting at character position m,n character long (if m is negative the count starts and the end of the character value . If n is omitted all characters to the end of the string are returned

Character Functions: Character Manipulation Functions These functions manipulate character strings. For example: Function Result LENGTH('HelloWorld') 10 SUBSTR('HelloWorld',1,5) Hello

Character Functions: Character Manipulation Functions (Cont.) Example: SELECT employee_id, job_id,LENGTH (last_name) FROM employees WHERE SUBSTR(job_id, 4) = 'REP';

Number Functions ROUND: Rounds value to specified decimal (Example 3) Syntax: ROUND(column|expression, n) :Rounds the column, expression, or value to n decimal places, or, if n is omitted, no decimal places. Example: ROUND(45.926, 2) 45.93

Number Functions TRUNC: Truncates value to specified decimal (Example 4) Syntax: TRUNC(column|expression,n) Truncates the column, expression, or value to n decimal places, or, if n is omitted, then n defaults to zero Example: TRUNC(45.926, 2) 45.92

Number Functions MOD: Returns remainder of division (Example 5) Syntax: MOD(m,n) Returns the remainder of m divided by n Example: MOD(1600, 300) 100

Example 3

Example 4

Example 5