In MariaDB, ASIN()
is a built-in numeric function that returns the square root of its argument.
Syntax
The syntax goes like this:
SQRT(X)
Where X
is the number for which to return the square root.
Example
Here’s an example:
SELECT SQRT(16);
Result:
+----------+ | SQRT(16) | +----------+ | 4 | +----------+
Here are some more examples:
SELECT
SQRT(0),
SQRT(1),
SQRT(17);
Result:
+---------+---------+-------------------+ | SQRT(0) | SQRT(1) | SQRT(17) | +---------+---------+-------------------+ | 0 | 1 | 4.123105625617661 | +---------+---------+-------------------+
Negative Argument
If the argument is negative, null
is returned.
Example:
SELECT SQRT(-16);
Result:
+-----------+ | SQRT(-16) | +-----------+ | NULL | +-----------+
Non-Numeric Argument
Here’s what happens when we provide a non-numeric argument:
SELECT SQRT('Four');
Result:
+--------------+ | SQRT('Four') | +--------------+ | 0 | +--------------+ 1 row in set, 1 warning (0.000 sec)
Let’s check the warning:
SHOW WARNINGS;
Result:
+---------+------+------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------+ | Warning | 1292 | Truncated incorrect DOUBLE value: 'Four' | +---------+------+------------------------------------------+
Invalid Argument Count
Calling SQRT()
without an argument results in an error:
SELECT SQRT();
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'SQRT'
And:
SELECT SQRT(4, 16);
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'SQRT'