The SQRT function in Oracle SQL is a straightforward mathematical function that returns the square root of a given number.
It's important to note that the SQRT function can only be used with non-negative numbers. Attempting to find the square root of a negative number (like -4) will result in an error.
What is the SQRT Function in Oracle?
The SQRT(n) function takes a single number n and returns its square root. The number n must be 0 or greater.
This function is commonly used in scientific, financial, and statistical calculations.
SQRT Function Syntax
The syntax for SQRT is very simple:
SQRT(n)
Let's break that down:
n(the number): The non-negative number for which you want to find the square root.
Oracle SQRT Function Examples
Here are two practical examples of how to use SQRT.
Example 1: Finding the Square Root of a Perfect Square
This example calculates the square root of 64, which is a perfect square.
Query:
SELECT
SQRT(64) AS "Square_Root_of_64"
FROM DUAL;
Result:
Square_Root_of_64
-----------------
8
Example 2: Finding the Square Root of a Non-Perfect Square
This example calculates the square root of 26. The result will be a decimal value.
Query:
SELECT
SQRT(26) AS "Square_Root_of_26"
FROM DUAL;
Result:
Square_Root_of_26
-----------------
5.09901951
