Acos Function In Sql in SQL
? ACOS() Function in SQL
The ACOS() function returns the arc cosine (inverse cosine) of a number — the angle (in radians) whose cosine is the specified number.
? Syntax
SELECT ACOS(number);Input Range:
-1to1Output: Value in radians between
0and?(approximately3.14159)
? Basic Example
SELECT ACOS(1) AS result;-- Output: 0.00000 (cos?¹(1) = 0 radians)SELECT ACOS(0) AS result;-- Output: 1.5707963 (cos?¹(0) = ?/2 radians)? With a Table Example
Assume a table angles:
| id | value |
|---|---|
| 1 | 0.5 |
| 2 | -0.5 |
| 3 | 1 |
Query:
SELECT id, value, ACOS(value) AS angle_in_radiansFROM angles;? Use Cases
Trigonometric calculations (especially in geometry, physics, or geolocation)
Great-circle distance (e.g., in Haversine formula for calculating distance between two lat/long points)
? Supported In
? MySQL
? PostgreSQL
? SQL Server (from SQL Server 2012+)
? Oracle
? Convert to Degrees
If you need the angle in degrees:
? MySQL:
SELECT DEGREES(ACOS(0.5)) AS degrees;-- Output: 60? PostgreSQL:
SELECT ACOS(0.5) * 180 / PI() AS degrees;-- Output: 60?? Notes
Input must be in the range
-1 to 1— otherwise, you'll get an error orNULL.Use
ROUND()orFORMAT()if you want to limit decimal places.
Let me know if you want to see it used in geolocation or geometry calculations!