MySQL PI() Function

The PI() function is used to return the value of π (pi), a mathematical constant representing the ratio of a circle's circumference to its diameter.


Syntax

PI()

Definition and Usage

  • Returns the value of π (approximately 3.141593).
  • Commonly used in mathematical calculations involving circles or trigonometry.
  • It is a constant, and the result is always the same.

Technical Details

  • Introduced in: MySQL 4.0
  • Return Value: A floating-point number representing π.

Examples

Example 1: Retrieve the value of π

SELECT PI() AS PiValue;

Output:

PiValue
--------
3.141593

Example 2: Calculate the circumference of a circle

To calculate the circumference of a circle with a radius of 5:

SELECT 2 * PI() * 5 AS Circumference;

Output:

Circumference
--------------
31.415926

Example 3: Calculate the area of a circle

To calculate the area of a circle with a radius of 3:

SELECT PI() * POW(3, 2) AS Area;

Output:

Area
-----
28.274334

Related Functions

  • DEGREES(): Converts a value in radians to degrees.
  • RADIANS(): Converts a value in degrees to radians.
  • POW(): Returns a number raised to the power of another number.

The PI() function is essential for geometric and trigonometric calculations in MySQL.


Was this article helpful?