ROUND returns n rounded to integer
places to the right of the decimal point. If you omit integer, then n is
rounded to 0 places. The argument integer can be negative to round off digits
left of the decimal point.
n can be any numeric data type or any
nonnumeric data type that can be implicitly converted to a numeric data type.
The argument integer must be an integer. If you omit integer, then the function
returns the same data type as the numeric data type of the argument. If you
include integer, then the function returns NUMBER.
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.
SQL
Function Round( ) Syntax:
SELECT
ROUND(column_name,decimals) FROM table_name;
SQL Function Round(
) Example:
Assumed that we have a table named “Products” given below.
|
ProductID
|
ProductName
|
SupplierID
|
CategoryID
|
Price
|
|
1
|
Coffee
|
1
|
1
|
18.3
|
|
2
|
Gula Malacca
|
1
|
1
|
19.6
|
|
3
|
Aniseed Syrup
|
1
|
2
|
10.7
|
|
4
|
Chocolate
|
2
|
2
|
21.35
|
|
5
|
Mutton
|
2
|
2
|
25.2
|
We are going to select Product Name and Price as rounded.
The syntax for
Format:
SELECT
ProductName, ROUND(Price,0) AS RoundedPrice
FROM
Products;
Output:
|
ProductName
|
RoundedPrice
|
|
Coffee
|
18
|
|
Gula Malacca
|
19
|
|
Aniseed Syrup
|
10
|
|
Chocolate
|
21
|
|
Mutton
|
25
|
|
Coffee
|
18
|
No comments:
Post a Comment