Open In App

PI() function in MySQL

Last Updated : 05 Oct, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
PI() function in MySQL is used to return the Pi value. The default number of decimal places displayed is seven, but MySQL uses the full double-precision value internally. Syntax :
PI()
Parameter : This method does not accept any parameter. Returns : It returns the Pi value i.e. 3.141593. Example-1 : Returning the default value of Pi using PI Function.
SELECT PI() AS DefaultPiValue;
Output :
DefaultPiValue 
  3.141593
Example-2 :

Returning the value of Pi up to 18 decimal places using PI Function .  

SELECT PI()+0.000000000000000000 
AS PiValue;
Output :
PiValue 
3.141592653589793000
Example-3 : Using PI Function to calculate the area and perimeter of all circles in a column. To demonstrate, let us create a table named Circle.
CREATE TABLE Circle(
Circle_id INT AUTO_INCREMENT,  
Radius DECIMAL(10, 3) NOT NULL,
PRIMARY KEY(Circle_id )
);
Now, insert some data to the Circle table.
INSERT INTO Circle(Radius )
VALUES
(2 ),(3),(10 ),(12.5 ),(6.80),
(4.60 ),(6),(20),(25) ;
So, the Circle Table is as follows.
SELECT * FROM Circle;
Circle_idRadius
12.000
23.000
310.000
412.500
56.800
64.600
76.000
820.000
925.000
Now, we will calculate the area and perimeter of every circle using PI function.
SELECT Circle_id, Radius,
PI() * Radius * Radius  AS Area,
2 * PI() * Radius AS Perimeter
FROM Circle;
Output :
Circle_idRadiusAreaPerimeter
12.00012.56637112.566371
23.00028.27433418.849556
310.000314.15926562.831853
412.500490.87385278.539816
56.800145.26724442.725660
64.60066.47610128.902652
76.000113.09733637.699112
820.0001256.637061125.663706
925.0001963.495408157.079633

Next Article
Article Tags :

Similar Reads