CBRT
Overview
The CBRT()
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 the CBRT()
function is as follows:
Where:
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.
For example, you can use expressions like SELECT CBRT(some_column) from test_table
, assuming some_column
contains a numeric value.
- 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 the CBRT()
function:
Case #1: Basic Cube Root Calculation
Consider the following example:
The result of this query will be:
Case #2: Cube Root of a Negative Value
To calculate the cube root of a negative number, use the CBRT()
function as shown:
The final result is as follows.
Case #3: Cube Root of Decimal Result
For calculations with decimal numbers, use the CBRT()
function as demonstrated below:
The result will be a decimal value, as shown below:
Case #4: Cube Root of Decimal Input
In this scenario, fractional seconds are incorporated into the argument:
The result will be the cube root of the provided decimal value.
Case #5: Handling Incorrect Argument
When a non-numeric argument is provided, the CBRT()
function works as follows:
An error will be generated, and the result will not be valid.
Case #6: CBRT Operator (||/(x)
)
Here’s an example using the CBRT operator (||/(x)
) to calculate the cube root of a given number:
In this example, we calculate the cube root of 1728 using the CBRT operator. The result of this query will be: