MySQL numeric manipulation functions

Explain the following functions with an example.

Abs(), Cos(), Exp(), Rand(), Sin(), Sqrt(), Tan(), Mod(), Pi()

1. Abs() : Returns the absolute value

Example:
Select abs(-32);

Output:
32

2. Cos() : Returns the cosine of parameter given in radians

Example:
Select cos(PI())

Output:
-1

3. Exp() : Returns the base of natural algorithms (e) ^ x.

Example:
Select EXP(2);

Output:
7.3890560989307

4. Rand() : Returns a random (ad hoc) floating point value

Example:
Select emp_id, RAND() from table_name;

5. Sin() : Returns the sine of parameter given in radians

Example:
Select sin(PI())

Output:
1.2246063538224e-16

6. Sqrt() : Returns the square root of a non negative integer

Example:
Select sqrt(9)

Output:
3

7. Tan() : Returns the tangent of parameter given in radians

Example:
Select tan(PI())

Output:
-1.2246063538224e-16

8. Mod() : Performs the modulo operation.Returns the remainder of N divided by M.

Example:
Select mod(10,3)

Output:
1

9. Pi() : Returns the value of p (pi).

Example:
Select pi();

Output:
3.141593
MySQL Group By
MySQL Group By is used along with aggregate functions to group the result-set by one or more columns.
MySQL Table
MySQL Table - What are the different tables present in MySQL?, How can we repair a MySQL table?, What are HEAP tables in MySQL?, Explain the capabilities of command ALTER table...
MySQL Data Type
MySQL Data Type - Difference between CHAR and VARCHAR column types, Difference between BLOB and text column types, ENUM and SET column type....
Post your comment