DBMS Lab 3
DBMS Lab 3
Q . 1 Execute all below functions on sample number, string and date values .
Function Description
ABS Returns the absolute value of a number.
AVG Returns the average value of an expression/column values.
CEILING Returns the nearest integer value which is larger than or equal to the specified decimal
value.
COUNT Returns the number of records in the SELECT query.
FLOOR Returns the largest integer value that is less than or equal to a number. The return value is
of the same data type as the input parameter.
MAX Returns the maximum value in an expression.
MIN Returns the minimum value in an expression.
RAND Returns a random floating point value using an optional seed value.
ROUND Returns a numeric expression rounded to a specified number of places right of the
decimal point.
SIGN Returns an indicator of the sign of the input integer expression.
SUM Returns the sum of all the values or only the distinct values, in the expression. NULL
values are ignored.
SQL Numeric Functions Aggregate Function
Example: ABS()
In the following example, the AVG() is used with the Salary column of the Employee table. It
calculates the average of all salaries and the average of distinct salaries.
Example: AVG()
PosInt =23
NegInt=-23
COUNT() Function
Parameters
ALL: Applies the aggregate function to all the values in the group. All values are counted.
This is the default value.
DISTINCT: Applies the aggregate function to only distinct not null values.
expression: An expression of any type except text, ntext, or image.
The * specifies that the COUNT() function should consider all rows to arrive at the total table
rows count.
• COUNT(*) returns the number of rows in a table. This includes duplicates and null
values.
• COUNT(*) does not take any other parameter and does not support DISTINCT.
• COUNT(*) does not need an expression as it does not use any information about any
particular column.
In this simple example, the COUNT(*) returns the total number of rows in the Employee table.
Example: COUNT(*)
The SIGN() function returns -1, 0, 1 based on the specified numeric value. It returns -1 for
any negative number, -1.0 for negative decimal, 1.0 for positive decimal, 1 for positive
integer, and 0 for 0 value.
SELECT SIGN (-234) AS SignNeg, SIGN (-0.45) AS DecNeg, SIGN (0) AS SignZero,
SIGN (0.45) AS DecPos, SIGN (234) AS SignPos
SELECT SUM(SALARY) FROM Employee;
Functions Description
lower() The SQL LOWER() function is used to convert all characters of a string to
lower case.
upper() The SQL UPPER() function is used to convert all characters of a string to
uppercase.
trim() The SQL TRIM() removes leading and trailing characters(or both) from a
character string.
LOWER(string)
UPPER(string)
TO_CHAR(number,format,parameters)
TO_NUMBER (‘353.78’);
TO_DATE
This function takes character values and returns the output in the date format.
The syntax of this function is given as follows −