// math reference

SQL DEGREES function

Converts an angle from radians to degrees: DEGREES(PI()) is 180 and DEGREES(PI()/2) is 90.

Категория
Math
Returns
double; SQL Server returns the input's type
In this category
39 of 82

Синтаксис

DEGREES(angle_radians)

Поддержка движка

ДвижокSupportЗаметки
SQL Server Да Returns the input's type: DEGREES(1) is 57, DEGREES(1.0) is 57.295779513082322865
PostgreSQL Да degrees(double precision) only; numeric input is cast to double
MySQL Да Built in
SQLite Да Built in on 3.35+
Oracle Not built in No DEGREES; use x * 180 / ACOS(-1)

Примеры

PostgreSQL

SELECT DEGREES(PI()) AS straight_angle;  -- 180

PostgreSQL

SELECT DEGREES(ASIN(0.5)) AS thirty_degrees;  -- 30.000000000000004

SQL Server

SELECT DEGREES(1) AS int_in, DEGREES(1.0) AS dec_in;  -- 57, 57.295779513082322865

Oracle

SELECT 0.5236 * 180 / ACOS(-1) AS degrees FROM dual;

Полезно знать

  • It is pure arithmetic: DEGREES(x) is x * 180 / PI(). On Oracle write x * 180 / ACOS(-1), since Oracle has neither DEGREES nor PI().
  • Trig functions stay radian-only on every engine; DEGREES is for display and for converting results like ASIN(0.5) into 30.
  • On SQL Server, DEGREES of an integer stays an integer and truncates: DEGREES(1) is 57, not 57.2958. Pass 1.0 or a float. Elsewhere small float noise appears instead: DEGREES(ASIN(0.5)) is 30.000000000000004.

Questions about DEGREES

What is the formula behind DEGREES?

x * 180 / PI(). On Oracle, which has neither function, write x * 180 / ACOS(-1).

Why does Oracle have no DEGREES?

It never shipped one, and it has no PI() either. Multiply manually: angle * 180 / ACOS(-1).

Does DEGREES make SIN accept degrees?

No. DEGREES converts radians to degrees, the opposite direction of what SIN needs. Convert degrees to radians with RADIANS() before calling trig functions.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.