Oracle SQRT Function: A Simple Guide

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
Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments