SQL SIN function
Returns the sine of an angle expressed in radians: SIN(0) is 0 and SIN(PI()) is about 1.2e-16, not exactly 0.
- 카테고리
- Math
- Returns
float / double- In this category
- 30 of 82
구문
SIN(angle_radians)
엔진 지원
| 엔진 | Support | 메모 |
|---|---|---|
| SQL Server | 예 | Supported under this name. |
| PostgreSQL | 예 | Supported under this name. |
| MySQL | 예 | Supported under this name. |
| SQLite | 예 | Requires SQLite 3.35+ with the math functions built in |
| Oracle | 예 | Supported under this name. |
예시
PostgreSQL
SELECT SIN(0) AS zero, SIN(PI()/6) AS half; -- 0, 0.49999999999999994
PostgreSQL
SELECT SIN(RADIANS(angle_deg)) AS sine FROM wave_samples;
SQL Server
SELECT SIN(30 * PI() / 180) AS sine_30; -- 0.49999999999999994
알아 두면 좋은 정보
- The argument is radians. Passing degrees without converting, SIN(30), computes the sine of 30 radians, a completely different angle.
- SIN(PI()) is about 1.2e-16, not 0: PI() is approximate, so the result of an exact-angle sine is only approximately exact.
- NULL in, NULL out: SIN of a NULL argument returns NULL on every engine.
Questions about SIN
Does SIN take degrees or radians?
Radians, on all five engines. Convert first: SIN(RADIANS(30)) or SIN(30 * PI() / 180) gives the sine of 30 degrees, 0.49999999999999994 in doubles. Oracle has neither RADIANS nor PI(), so write SIN(30 * ACOS(-1) / 180).
Why is SIN(PI()) not exactly 0?
PI() is a double approximation of pi, so PI() is not exactly the angle whose sine is zero. The result is about 1.2e-16: effectively zero, but not literally.
What does SIN return for NULL input?
NULL. Every trig function propagates NULL, so rows with missing angles simply come back NULL rather than erroring.
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, Oracle.
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.