SQL Tutorial SQL Advanced SQL Database SQL References

MySQL PI() Function



The MySQL PI() function returns the value of 𝜋 (pi) displayed with 6 decimal places.

Note: This function displays the value of 𝜋 with only 6 decimal places. However, internally it uses the double-precision value when used in calculations with other double-precision values.

Syntax

PI()

Parameters

No parameter is required.

Return Value

Returns the value of 𝜋.

Example 1:

The example below shows the usage of PI() function.

mysql> SELECT PI();
Result: 3.141593

mysql> SELECT PI() * 1;
Result: 3.141593

mysql> SELECT PI() * 1.00;
Result: 3.141593

mysql> SELECT PI() * 1.00000000000000;
Result: 3.14159265358979

Example 2:

Consider a database table called Sample with the following records:

DataRadius
Data 11
Data 22
Data 33
Data 44
Data 55

The statement given below can be used to calculate the area of the circle where radius is specified by values of column Radius.

SELECT *, (PI() * Radius * Radius) AS Area FROM Sample;

This will produce the result as shown below:

DataRadiusArea
Data 113.141593
Data 2212.566371
Data 3328.274334
Data 4450.265482
Data 5578.539816

❮ MySQL Functions