Hi everyone, we continue with the topic of functions. You can read the previous functions article here.
Raund Function
Used to round the numeric values that result from a SQL query to an upper or lower integer.
Usage of: Select round(column_name, number of digits to exclude) from table name
SELECT PROD_LIST_PRICE FROM SH.PRODUCTS;
If you want to print on the screen by round function according to the upper or lower value.
Trunct Function
It is used to shorten the numerical values that result from the SQL query according to the desired decimal number.
Usage of: Select trunc (column_name, number of digits to subtract) from table_name;
SELECT PROD_LIST_PRICE FROM SH.PRODUCTS;
SELECT TRUNC(PROD_LIST_PRICE,1) FROM SH.PRODUCTS ORDER BY PROD_LIST_PRICE ASC;
As shown in the picture, a digit was omitted after the comma.
Mod function
Used to represent the remainder of the numerical values from the integer part.
Usage of: Select Mod (column_name, integer to divide) from table_name;
Let’s create a query by combining the functions we just saw.
SELECT PROD_LIST_PRICE FROM SH.PRODUCTS order by prod_list_price;
Let’s use multiple function,
select mod(round(prod_list_price,0),3) from sh.products order by prod_list_price;
As shown in the picture, we first rounded with the round function, then we took the mode of the rounded number.
See you in the next article..