3.sql Functions
3.sql Functions
syllabus
Informatics Practices 2023-24
Chapter 3
Database query using sql –
functions and data reporting
Basically, it is a set of SQL statements that accept only input parameters, perform
actions and return the result. A function can return an only a single value or a table.
Functions are not alternate to sql commands but are used as a part of sql
command(generally select command).
Types of Function(System defined)
A scalar function is a function that operates on scalar values -- that is, it takes one (or
more) input values as arguments directly and returns a value.Maths,text, date
functions etc. These functions can be applied over column(s) of a table to perform
relevant operation on value of each record.
For e.g. select left(name,4) from student;
Will display 4 left side letters of each row of name field from student table.
An aggregate function is a function that operates on aggregate data -- that is, it takes
a complete set of data as input and returns a value that is computed from all the
values in the set. E.g. max(), min(), count(), sum(), avg().Generally these are used for
report preparation & mostly used with group by and having clause.
Mathematical functions
MOD() – The MOD() function returns the remainder of one
number divided by another. The following shows the syntax of
the MOD() function:
Syntax - MOD(dividend,divisor)
Dividend - is a literal number or a numeric expression to divide.
Divisor- is a literal number or a numeric expression by which to
divide the dividend.
E.g.
Mysql> SELECT MOD(11, 3);
Mysql>2
Mysql> SELECT MOD(10.5, 3);
Mysql>1.5
Visit : python.mykvs.in for regular updates
SQL functions