You are on page 1of 7

Number Functions

Single Row Functions


Objectives

Select and apply the single-row number functions


ROUND, TRUNC, and MOD in a SQL query
Number Functions

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

OEHB
Purpose

One of the reasons we put our


money in a bank is to take If a bank decided to round the
percentage rate to 3.5%, would it be to
advantage of the interest it your advantage?
accumulates over time.
Number Functions

Banks adjust the interest rate


with various economic If it decided to just drop the decimal
values and calculate the interest at 3%,
indicators such as inflation and would you be happy then?
the stock market.

Rounding and truncating numbers play an


Typically, interest rates are important part in business and in turn
expressed as a percent such as with the databases that support these
3.45%. businesses as they store and access
numeric data.

OEHB
Number Functions

ROUND TRUNC
Number Functions

MOD

OEHB
Round
} ROUND can be used with both numbers and dates.
} It is mainly used to round numbers to a specified number of decimal places,
but it can also be used to round numbers to the left of the decimal point.
Number Functions

} ROUND(45.926) à 46
} ROUND(45.926, 0) à 46

} ROUND(45.926, 2) à 45.93

} ROUND(45.926, -1) à 50

OEHB
TRUNC
} TRUNC
} Can be used with both numbers and dates.
} It is mainly used to terminate the column, expression, or value to a specified
number of decimal places.
Number Functions

} TRUNC (45.926, 2) à 45.92

} TRUNC (45.926, 0) à 45
} TRUNC (45.926) à 45

OEHB
MOD
} MOD can be used to determine } MOD(5,2) à 1
whether a value is odd or } MOD(4,2) à 0
even.
} If you divide a value by 2 and
Number Functions

there is no remainder, the number


must be an even number.
} 1 means the number is odd,
} 0 means that it is even.

} MOD is multiple of X
} Ex.: MOD(9,3) à 0
} Because Is Multiple of 3

OEHB

You might also like