Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Acos Function In Sql in SQL

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: -1 to 1

  • Output: Value in radians between 0 and ? (approximately 3.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:

idvalue
10.5
2-0.5
31

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 or NULL.

  • Use ROUND() or FORMAT() if you want to limit decimal places.


Let me know if you want to see it used in geolocation or geometry calculations!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql