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.
The syntax for the CBRT() 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.
For example, you can use expressions like SELECT CBRT(some_column) from test_table, assuming some_column contains a numeric value.
Return 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.
Below are several usage examples of the CBRT() function:
Consider the following example:
The result of this query will be:
To calculate the cube root of a negative number, use the CBRT() function as shown:
The final result is as follows.
For calculations with decimal numbers, use the CBRT() function as demonstrated below:
The result will be a decimal value, as shown below:
In this scenario, fractional seconds are incorporated into the argument:
The result will be the cube root of the provided decimal value.
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.
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: