Lecture 5 SQL FUNCTIONS.

Slides:



Advertisements
Similar presentations
Manipulating Strings String Functions. VB provides a large number of functions that facilitate working with strings. These are found in Microsoft.VisualBasic.Strings.
Advertisements

Copyright  Oracle Corporation, All rights reserved. 2 Single-Row Functions.
Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
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.
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.
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.
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.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
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.
Chapter 3 Selected Single-Row Functions and Advanced DML & DDL.
A Guide to SQL, Seventh Edition. Objectives Understand how to use functions in queries Use the UPPER and LOWER functions with character data Use the ROUND.
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
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.
Copyright س Oracle Corporation, All rights reserved. 3 Single-Row Functions.
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.
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
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.
College of Information Technology, Universiti Tenaga Nasional1 Lab 2: Single-row Functions CISB224 01A CCSB244 01A Semester I, 2008/2009.
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.
Create Stored Procedures and Functions Database Management Fundamentals LESSON 2.4.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
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.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Logical Functions Excel Lesson 10.
String Methods Programming Guides.
In this session, you will learn to:
Open Source Server Side Scripting MySQL Functions
A Guide to SQL, Seventh Edition
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
MARK CARPENTER, Ph.D. Introduction to SAS Programming and Applications
Restricting and Sorting Data
The Selection Structure
SQL DATE/TIME FUNCTIONS
Computations Done on table data
Using Single-Row Functions to Customize Output
SQL Text Manipulation Farrokh Alemi, Ph.D.
Chapter 7: Strings and Characters
المحاضرة 4 دوال الصف الواحد.
Date Functions Farrokh Alemi, Ph.D.
Single-Row Functions Lecture 9.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Inside Module 8 Extracting Data Page Using the Extract command 2
Trainer: Bach Ngoc Toan– TEDU Website:
Presentation transcript:

Lecture 5 SQL FUNCTIONS

Functions are a very powerful feature of SQL Functions are a very powerful feature of SQL. They can be used to do the following: Perform calculations on data Modify individual data items Manipulate output for groups of rows Format dates and numbers for display Convert column data types SQL functions sometimes take arguments and always return a value.

Types of SQL functions There are two types of functions: Single-row functions Multiple-row 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. Character Number Date Conversion General

Multiple-Row Functions Functions can manipulate groups of rows to give one result per group of rows. These functions are also known as group functions. Example: Avg(),count(),max(),min(),sum()

Single Row Function Description Manipulate data items Accept arguments and return one value Act on each row that is returned Return one result per row May modify the data type

Type of Argument in the Function User-supplied constant Variable value Column name Expression. Single row functions can be used in SELECT,WHERE,ORDERBY clauses.

Function_name(arg1,arg2…) Syntax function_name is the name of the function, arg1, arg2 is any argument to be used by the function. This can be represented by a column name or expression. Function_name(arg1,arg2…)

Type of Single Row Functions  Character functions: Αccept character input and can return both character and number values Number functions: Accept numeric input and return numeric values Date functions: Operate on values of the DATE data type. Conversion functions: Convert a value from one data type to another General functions: - NVL,NVL2,NULLIF,CASE,DECODE

Character Function Two types: Case conversion function. Character manipulation functions.

Case Conversion Function LOWER, UPPER LOWER Converts alpha character values to lowercase SELECT LOWER(ENAME) FROM employee

UPPER: Converts alpha character values to uppercase. SELECT UPPER(ENAME) FROM employee

Character Manipulation Function CONCAT,SUBSTR.LENGTH,TRIM CONCAT: Joins values together (You are limited to using two parameters with CONCAT.) SELECT CONCAT(ENAME,EMPLNO) FROM employee • SUBSTR: Extracts a string of determined length SELECT SUBSTR(ENAME,1,5)

LENGTH: Shows the length of a string as a numeric value SELECT length(ENAME) FROM employee • INSTR: Finds numeric position of a named character SELECT INSTR(ENAME,'A')

Replace Replace lets you substitute one string for another as well as to remove character strings. Select replace(‘JACK’, ‘J’, ‘BL’); Output: BLACK Reverse: Reverse characters in a string Select reverse(‘abcd’); Output: dcba

MID() Used to extract character from the text field. MID(name, 1 ,4)

Number Function ROUND: Rounds value to a specified decimal Result: 45.44 TRUNC: Truncates value to a specified decimal TRUNCATE(45.436,2) Result: 45.43 MOD: Returns remainder of division MOD(1600,300) Result: 100

Controlling for number precision Ceil and floor functions are used to round either up or down to the closest integer. Select ceil(72.445) 73 floor(72.445) 72

DATE FUNCTIONS Used to perform date calculations or format date values. MYSQL displays date in this format'YYYY-MM-DD'  Curdate() for retrieving current date. CURTIME() for retrieving current time NOW() for retrieving time and date.