Topics Covered

# MySQL Functions

Functions are commands written with required values as parameters to fulfill various tasks related to calculations or logical comparison or displaying statistics from the database. Consider the following database table for all functions:

## Math Functions

Math functions allows to do mathematical computations in MySQL. The functions given in your syllabus are as following:

**Power:**It is used to compute power of given value as parameter.

Syntax: power(value or column)

Example:

- Value: Select power(3,3), the output will be

- Column
**:**select power(rollno, 2) from students;

**Round:**It is used to display the number to nearest number with rounding up if the next digit is more than 5.

Syntax: round(value or column, digits)

**Mod:**This function returns the remainder after division of the number with divisor.

Syntax: select mod(value or column, divisor)

Example: select mod(53,3)m

More functions not given in your syllabus

**SQRT**: This function returns square root of given number.

Syntax: select sqrt(value or column)

**ABS:**This function returns the number into positive number as an absolute value.

Syntax: select abs(value or column)

**Truncate:**This function returns a number after removing specified digits as parameter.

Syntax: select truncate(value or column, digits)

**Sign:**It will return 1 if the number is positive and returns -1 if the number is negative.

Syntax: select sign(value or number)

# Text Functions

The text functions are used to manipulate the text based data used in database and display the results.

**UCASE/UPPER**: This function is used to convert the text into upper case i.e. into capital.

Syntax: select ucase(â€˜textâ€™ or column) or select upper(â€˜textâ€™ or column)

**Lcase/lower:**This function is used to convert the enclosed text into lower case i.e. small letters.

Syntax: select lcase(â€˜textâ€™ or column) or lower(â€˜textâ€™ or column)

**Mid:**This function returns the text starting from a specified number of letters to a specified letter from the enclosed text or column value.

Syntax: select mid(â€˜Textâ€™ or column, start_pos, end_pos)

Substring and substr is also used for the same.

**Length:**This function returns the number of letters from the text including white space.

Syntax: select substr(â€˜textâ€™ or column)

**Left**: This function is used to return specified left side letters from the enclosed text or column values.

Syntax: select left(â€˜textâ€™ or column, no_of_characters)

**Right:**It is exactly reverse than left, display the result from right side of selected text.

Syntax: right(â€˜textâ€™ or column, no_of_characters)

**Instr():**It will check the specified text from the enclosed text and return a number from where the specified text is starting.

Syntax: select instr(â€˜textâ€™ or column,â€™text_to_searchâ€™)

Click here to read all contents