SQL TAN function
Returns the tangent of an angle expressed in radians: TAN(0) is 0 and the result grows without bound near PI()/2.
- 类别
- Math
- Returns
float / double- In this category
- 32 of 82
语法
TAN(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 TAN(0) AS zero, TAN(PI()/4) AS one; -- 0, 0.9999999999999999
PostgreSQL
SELECT TAN(RADIANS(slope_deg)) AS rise_over_run FROM grades;
SQL Server
SELECT TAN(PI()/2) AS huge; -- about 1.63e16, not infinity
值得了解
- There is no vertical asymptote error: TAN(PI()/2) returns about 1.6e16, a huge finite value, because PI()/2 in floats is not exactly a right angle.
- The argument is radians; TAN(45) is the tangent of 45 radians, not 45 degrees.
- Results can be anything (there is no [-1, 1] bound like SIN and COS), so plausibility checks tuned for those will not transfer.
Questions about TAN
What does TAN(PI()/2) return?
A huge finite number, about 1.6e16, not an error and not infinity: PI()/2 as a double is not exactly a right angle, so the tangent is defined but enormous.
Why does TAN give a wild value for my angle?
Either the angle is in degrees and you passed radians, or it sits near PI()/2 where tangent is mathematically unbounded. Convert with RADIANS() and check proximity to right angles.
Does TAN ever error?
Only on invalid input types. The tangent itself is defined everywhere except exact right angles, which floats never hit exactly, so engines return large finite numbers.
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.