Overview
TheCBRT()
function calculates and returns the cube root of a given number. In mathematical terms, for a number x, its cube root y is determined by the equation y³ = x.
Syntax
The syntax for theCBRT()
function is as follows:
number
: This is a required value representing the number for which you want to calculate the cube root. It can be a positive or negative whole number, a decimal, or even an expression that evaluates to a number.
SELECT CBRT(some_column) from test_table
, assuming some_column
contains a numeric value.
Return Value:
- It will return
- It will give an error if you input a parameter that is not a numeric type.
- It will return
NULL
if the argument is NULL
. - It will give an error if you input a parameter that is not a numeric type.
Examples
Below are several usage examples of theCBRT()
function:
Case #1: Basic Cube Root Calculation
Consider the following example:Case #2: Cube Root of a Negative Value
To calculate the cube root of a negative number, use theCBRT()
function as shown:
Case #3: Cube Root of Decimal Result
For calculations with decimal numbers, use theCBRT()
function as demonstrated below:
Case #4: Cube Root of Decimal Input
In this scenario, fractional seconds are incorporated into the argument:Case #5: Handling Incorrect Argument
When a non-numeric argument is provided, theCBRT()
function works as follows:
Case #6: CBRT Operator (||/(x)
)
Here’s an example using the CBRT operator (||/(x)
) to calculate the cube root of a given number: