Number Functions. 2 home back first prev next last Review single-row character functions –character case-manipulation functions  LOWER, UPPER, INITCAP.

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.
Maths & Trig, Statistical functions. ABS Returns the absolute value of a number The absolute value of a number is the number without its sign Syntax ◦
The Decimal Number System
Introduction to Oracle9i: SQL1 Selected Single-Row Functions.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 – Part 2 Wanda M. Kunkle.
Bell Work: If 479 stocks advanced in price and 326 declined in price, then what was the approximate ratio of advancers to decliners?
4.5 Changing a Decimal or Fraction to a Percent 1 Converting a Decimal to a Percent To convert from a decimal to a percent, we will now multiply by “100”.
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.
Percents Greater Than 100% or Less Than 1%
Oracle FUNCTIONS. Comment ScreenShot (in 10g) General Example of null Foreign Key: create table deptcs( deptno NUMBER(4) primary key, hiredate DATE,
ALGEBRA 1. Lesson 1-3 Warm-Up ALGEBRA 1 Lesson 1-3 Warm-Up.
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
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.
Input, Output, and Processing
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.
PRESENTATION 2 Percents. PERCENTS Indicates number of hundredths in a whole A decimal fraction can be expressed as a percent by moving the decimal point.
Lesson 1.7 Dividing Integers Standards: NS 1.2 and AF 2.1 Objectives: Dividing Integers Evaluate variable expressions.
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.
SQL SELECT QUERIES CS 260 Database Systems. Overview  Introduction to SQL  Single-table select queries  Using the DBMS to manipulate data output 
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 3 Selected Single-Row Functions and Advanced DML & DDL.
6 Copyright © 2006, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
EXPRESSION Transformation. Introduction ►Transformations help to transform the source data according to the requirements of target system and it ensures.
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.
Introduction to Functions – Single Row Functions.
Using Functions in SQL Statements. 2 home back first prev next last What Will I Learn? List the advantages of user-defined functions in SQL statements.
Using Single-Row Functions to Customize Output
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.
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.
Welcome to Yr 5 with Mrs Hall, Miss Moses and Mr Wells.
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
Defining a Column Alias
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.
Fraction – decimal Fraction – percent Decimal – fraction Decimal – percent Percent – decimal Percent – fraction.
Numeric Functions Purpose:-
Open Source Server Side Scripting MySQL Functions
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Restricting and Sorting Data
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
SQL 101 3rd Session.
Using Single-Row Functions to Customize Output
دوال حرفية دوال رقميه دوال تاريخ دوال تحويل
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
Review Mathematics Skills
Lecture 5 SQL FUNCTIONS.
Presentation transcript:

Number Functions

2 home back first prev next last Review single-row character functions –character case-manipulation functions  LOWER, UPPER, INITCAP –character-manipulation functions  CONCAT, SUBSTR,  LENGTH, INSTR  LPAD, RPAD  TRIM  REPLACE

3 home back first prev next last What Will I Learn? single-row number functions –ROUND, TRUNC, and MOD –Distinguish between TRUNC and ROUND when they are applied to a numeric value –State the implications for business when applying TRUNC and ROUND to numeric values

4 home back first prev next last Why Learn It? One of the reasons we put our money in a bank is to take advantage of the interest it accumulates over time. Banks adjust the interest rate with various economic indicators such as inflation and the stock market. Typically, interest rates are expressed as a percent such as 3.45%.

5 home back first prev next last Why Learn It? What if a bank decided to round the percentage rate to 3.5%? Would it be to your advantage? What if they decided to just drop the decimal values and calculate the interest at 3%, would you be happy then? Rounding and truncating numbers play an important part in business and in turn with the databases that support these businesses as they store and access numeric data.

6 home back first prev next last number functions accept numeric input and return numeric values The three number functions are: –ROUND –TRUNC –MOD

7 home back first prev next last ROUND Used to round numbers to a specified number of decimal places. ROUND can also be used to round numbers to the left of the decimal point. ROUND can also be used with dates. Syntax –ROUND(column|expression, decimal places) select round(2.55,1) from dual;

8 home back first prev next last ROUND If the number of decimal places is a positive number, the number is rounded to that number of decimal places. If the number of decimal places is a negative number, numbers to the left of the decimal are rounded. if the number of decimal places is not specified or is zero, the number will round to no decimal places.

9 home back first prev next last ROUND For NUMBER values, the value n is rounded away from 0 (for example, to x +1 when x.5 is positive and to x -1 when x.5 is negative). For BINARY_FLOAT and BINARY_DOUBLE values, the function rounds to the nearest even value. Please refer to the examples that follow.

10 home back first prev next last TRUNC Used to terminate the column,expression, or value to a specified number of decimal places. TRUNC can also be used with dates. Syntax –TRUNC(column|expression, decimal places)  TRUNC (45.926, 2) yields if the TRUNC expression does not specify the number of decimal places or specifies a zero, the number is truncated to zero decimal places.  TRUNC (45.926) yields 45

11 home back first prev next last TRUNC For NUMBER and BINARY_FLOAT and BINARY_DOUBLE values, the rule is the same now.

12 home back first prev next last MOD Used to return the remainder when one number is divided by another. –For example, the MOD of 5 divided by 2 = 1.

13 home back first prev next last MOD Returns n2 if n1 is 0. This function behaves differently from the classical mathematical modulus function when m is negative. The classical modulus can be expressed using the MOD function with this formula: m - n * FLOOR(m/n) FLOOR(n) returns largest integer equal to or less than n.

14 home back first prev next last MOD MOD can be used to determine whether a value is odd or even. –If MOD(n,2) equals 0,n is even –If MOD(n,2) equals 1,n is odd SELECT last_name, salary FROM f_staffs WHERE MOD(salary, 2)=0;  The above query will show the staffs whose salary is an even number.

15 home back first prev next last Terminology Key terms used in this lesson include: –Number functions –MOD –ROUND –TRUNC

16 home back first prev next last Summary Select and apply the single-row number functions ROUND, TRUNC, and MOD in a SQL query Distinguish between the results obtained when TRUNC is applied to a numeric value and ROUND is applied to a numeric value State the implications for business when applying TRUNC and ROUND to numeric values