SQL RADIANS function
Converts an angle from degrees to radians: RADIANS(180) is PI() and RADIANS(90) is about 1.5708.
- Категория
- Math
- Returns
double; SQL Server returns the input's type- In this category
- 40 of 82
Синтаксис
RADIANS(angle_degrees)
Поддержка движка
| Движок | Support | Заметки |
|---|---|---|
| SQL Server | Да | Returns the input's type: RADIANS(180) is 3, RADIANS(180.0) is 3.141592653589793116 |
| PostgreSQL | Да | radians(double precision) only |
| MySQL | Да | Built in |
| SQLite | Да | Built in on 3.35+ |
| Oracle | Not built in | No RADIANS; use x * ACOS(-1) / 180 |
Примеры
PostgreSQL
SELECT RADIANS(180) AS pi_value; -- 3.141592653589793
SQL Server
SELECT RADIANS(180) AS int_in, RADIANS(180.0) AS dec_in; -- 3, 3.141592653589793116
PostgreSQL
SELECT SIN(RADIANS(30)) AS half; -- 0.49999999999999994
Oracle
SELECT 30 * ACOS(-1) / 180 AS radians FROM dual;
Полезно знать
- It is x * PI() / 180. On Oracle, spell it out: angle * ACOS(-1) / 180.
- SQL Server truncates integer input: RADIANS(180) is 3 and RADIANS(30) is 0, so SIN(RADIANS(30)) is 0 there. Write RADIANS(30.0) or RADIANS(CAST(x AS FLOAT)).
- The most common trig bug is skipping it: SIN(30) computes 30 radians. RADIANS(30) then SIN gives the intended 0.5.
Questions about RADIANS
What is the formula behind RADIANS?
x * PI() / 180. On Oracle, which lacks the function, write angle * ACOS(-1) / 180.
Why do I need RADIANS at all?
Every SQL trig function takes radians. Passing degrees computes the wrong angle silently: SIN(30) is the sine of 30 radians, about -0.988, not 0.5.
Is RADIANS(180) exactly pi?
It is the closest double to pi, accurate to about 16 digits, which is why SIN(RADIANS(180)) returns 1.2e-16 instead of 0. On SQL Server, RADIANS(180) with an integer argument is just 3.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite.
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.