SQRT
SQRT is a mathematical function provided by SQL, which is used to calculate the square root of a specified number.
SQRT(X)
- x: The number for which the square root is to be calculated. It must be a positive number or zero. If the value of X is negative, the function returns NULL.
Example
SELECT SQRT(4);
Output
2
Explanation
In this example, the SQRT() function is used to return the square root of 4, which is 2.
SQRT(double precision)
- double precision: This parameter denotes the numeric value for which the square root is to be calculated. It should fall within the range of a double precision floating-point number in PostgreSQL. The function returns a double precision number representing the square root of the input value.
Example
SELECT SQRT(25);
Output
| sqrt ||--------|| 5.0 |
Explanation
The SQRT
function in PostgreSQL is used to calculate the square root of a number. In this example, SQRT
is used to find the square root of 25 which is 5.
SQRT( float_expression )
- float_expression: This is a floating-point number or an expression that can implicitly be converted to a floating point number, which is required as an input parameter. It represents the value to apply the square root operation. If a negative number, NULL, or a non-numeric string is passed, an error or NULL is returned respectively.
Example
SELECT SQRT(81);
Output
9
Explanation
In this example, we used the SQRT
function from SQL Server to calculate the square root of 81. The output of the function is 9, as the square root of 81 is 9.
SQRT(n)
- n: This parameter stands for a numeric or float expression, which must be non-negative. The SQRT function will return the square root of this value.
Example
SELECT SQRT(16) AS "Square Root" FROM dual;
Output
Square Root-----------4
Explanation
The SQL code above uses Oracle’s SQRT
function to compute the square root of 16. The AS
keyword is used to rename the column in the output as “Square Root”. The FROM dual
clause is a dummy Oracle table used for computations or variable selections. The output of the command is 4, which is the square root of 16.
SQRT(X)
- x: This parameter represents a number or an expression from which the square root is to be calculated. The value must be a valid floating-point or integer type.
Example
SELECT SQRT(16);
Output
4.0
Explanation
The SQRT function in SQL returns the square root of a specified number. In this example, SQRT function is used to find the square root of number 16. As expected, it returns 4.0 which is the square root of 16.