math.asciidoc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. [role="xpack"]
  2. [[sql-functions-math]]
  3. === Mathematical Functions
  4. All math and trigonometric functions require their input (where applicable)
  5. to be numeric.
  6. [[sql-functions-math-generic]]
  7. [discrete]
  8. === Generic
  9. [[sql-functions-math-abs]]
  10. ==== `ABS`
  11. .Synopsis:
  12. [source, sql]
  13. --------------------------------------------------
  14. ABS(numeric_exp) <1>
  15. --------------------------------------------------
  16. *Input*:
  17. <1> numeric expression. If `null`, the function returns `null`.
  18. *Output*: numeric
  19. *Description*: Returns the {wikipedia}/Absolute_value[absolute value] of `numeric_exp`. The return type is the same as the input type.
  20. ["source","sql",subs="attributes,macros"]
  21. --------------------------------------------------
  22. include-tagged::{sql-specs}/docs/docs.csv-spec[abs]
  23. --------------------------------------------------
  24. [[sql-functions-math-cbrt]]
  25. ==== `CBRT`
  26. .Synopsis:
  27. [source, sql]
  28. --------------------------------------------------
  29. CBRT(numeric_exp) <1>
  30. --------------------------------------------------
  31. *Input*:
  32. <1> numeric expression. If `null`, the function returns `null`.
  33. *Output*: double numeric value
  34. *Description*: Returns the {wikipedia}/Cube_root[cube root] of `numeric_exp`.
  35. ["source","sql",subs="attributes,macros"]
  36. --------------------------------------------------
  37. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCbrtWithNegativeValue]
  38. --------------------------------------------------
  39. [[sql-functions-math-ceil]]
  40. ==== `CEIL/CEILING`
  41. .Synopsis:
  42. [source, sql]
  43. --------------------------------------------------
  44. CEIL(numeric_exp) <1>
  45. --------------------------------------------------
  46. *Input*:
  47. <1> numeric expression. If `null`, the function returns `null`.
  48. *Output*: integer or long numeric value
  49. *Description*: Returns the smallest integer greater than or equal to `numeric_exp`.
  50. ["source","sql",subs="attributes,macros"]
  51. --------------------------------------------------
  52. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCeiling]
  53. --------------------------------------------------
  54. [[sql-functions-math-e]]
  55. ==== `E`
  56. .Synopsis:
  57. [source, sql]
  58. --------------------------------------------------
  59. E()
  60. --------------------------------------------------
  61. *Input*: _none_
  62. *Output*: `2.718281828459045`
  63. *Description*: Returns {wikipedia}/E_%28mathematical_constant%29[Euler's number].
  64. ["source","sql",subs="attributes,macros"]
  65. --------------------------------------------------
  66. include-tagged::{sql-specs}/docs/docs.csv-spec[mathEulersNumber]
  67. --------------------------------------------------
  68. [[sql-functions-math-exp]]
  69. ==== `EXP`
  70. .Synopsis:
  71. [source, sql]
  72. --------------------------------------------------
  73. EXP(numeric_exp) <1>
  74. --------------------------------------------------
  75. *Input*:
  76. <1> float numeric expression. If `null`, the function returns `null`.
  77. *Output*: double numeric value
  78. *Description*: Returns {wikipedia}/Exponential_function[Euler's number at the power] of `numeric_exp` e^numeric_exp^.
  79. ["source","sql",subs="attributes,macros"]
  80. --------------------------------------------------
  81. include-tagged::{sql-specs}/docs/docs.csv-spec[mathExpInline]
  82. --------------------------------------------------
  83. [[sql-functions-math-expm1]]
  84. ==== `EXPM1`
  85. .Synopsis:
  86. [source, sql]
  87. --------------------------------------------------
  88. EXPM1(numeric_exp) <1>
  89. --------------------------------------------------
  90. *Input*:
  91. <1> float numeric expression. If `null`, the function returns `null`.
  92. *Output*: double numeric value
  93. *Description*: Returns https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#expm1-double-[Euler's number at the power] of `numeric_exp` minus 1 (e^numeric_exp^ - 1).
  94. ["source","sql",subs="attributes,macros"]
  95. --------------------------------------------------
  96. include-tagged::{sql-specs}/docs/docs.csv-spec[mathExpm1Inline]
  97. --------------------------------------------------
  98. [[sql-functions-math-floor]]
  99. ==== `FLOOR`
  100. .Synopsis:
  101. [source, sql]
  102. --------------------------------------------------
  103. FLOOR(numeric_exp) <1>
  104. --------------------------------------------------
  105. *Input*:
  106. <1> numeric expression. If `null`, the function returns `null`.
  107. *Output*: integer or long numeric value
  108. *Description*: Returns the largest integer less than or equal to `numeric_exp`.
  109. ["source","sql",subs="attributes,macros"]
  110. --------------------------------------------------
  111. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineFloor]
  112. --------------------------------------------------
  113. [[sql-functions-math-log]]
  114. ==== `LOG`
  115. .Synopsis:
  116. [source, sql]
  117. --------------------------------------------------
  118. LOG(numeric_exp) <1>
  119. --------------------------------------------------
  120. *Input*:
  121. <1> numeric expression. If `null`, the function returns `null`.
  122. *Output*: double numeric value
  123. *Description*: Returns the {wikipedia}/Natural_logarithm[natural logarithm] of `numeric_exp`.
  124. ["source","sql",subs="attributes,macros"]
  125. --------------------------------------------------
  126. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineLog]
  127. --------------------------------------------------
  128. [[sql-functions-math-log10]]
  129. ==== `LOG10`
  130. .Synopsis:
  131. [source, sql]
  132. --------------------------------------------------
  133. LOG10(numeric_exp) <1>
  134. --------------------------------------------------
  135. *Input*:
  136. <1> numeric expression. If `null`, the function returns `null`.
  137. *Output*: double numeric value
  138. *Description*: Returns the {wikipedia}/Common_logarithm[base 10 logarithm] of `numeric_exp`.
  139. ["source","sql",subs="attributes,macros"]
  140. --------------------------------------------------
  141. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineLog10]
  142. --------------------------------------------------
  143. [[sql-functions-math-pi]]
  144. ==== `PI`
  145. .Synopsis:
  146. [source, sql]
  147. --------------------------------------------------
  148. PI()
  149. --------------------------------------------------
  150. *Input*: _none_
  151. *Output*: `3.141592653589793`
  152. *Description*: Returns {wikipedia}/Pi[PI number].
  153. ["source","sql",subs="attributes,macros"]
  154. --------------------------------------------------
  155. include-tagged::{sql-specs}/docs/docs.csv-spec[mathPINumber]
  156. --------------------------------------------------
  157. [[sql-functions-math-power]]
  158. ==== `POWER`
  159. .Synopsis:
  160. [source, sql]
  161. --------------------------------------------------
  162. POWER(
  163. numeric_exp, <1>
  164. integer_exp) <2>
  165. --------------------------------------------------
  166. *Input*:
  167. <1> numeric expression. If `null`, the function returns `null`.
  168. <2> integer expression. If `null`, the function returns `null`.
  169. *Output*: double numeric value
  170. *Description*: Returns the value of `numeric_exp` to the power of `integer_exp`.
  171. ["source","sql",subs="attributes,macros"]
  172. --------------------------------------------------
  173. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlinePowerPositive]
  174. --------------------------------------------------
  175. ["source","sql",subs="attributes,macros"]
  176. --------------------------------------------------
  177. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlinePowerNegative]
  178. --------------------------------------------------
  179. [[sql-functions-math-random]]
  180. ==== `RANDOM/RAND`
  181. .Synopsis:
  182. [source, sql]
  183. --------------------------------------------------
  184. RANDOM(seed) <1>
  185. --------------------------------------------------
  186. *Input*:
  187. <1> numeric expression. If `null`, the function returns `null`.
  188. *Output*: double numeric value
  189. *Description*: Returns a random double using the given seed.
  190. ["source","sql",subs="attributes,macros"]
  191. --------------------------------------------------
  192. include-tagged::{sql-specs}/docs/docs.csv-spec[mathRandom]
  193. --------------------------------------------------
  194. [[sql-functions-math-round]]
  195. ==== `ROUND`
  196. .Synopsis:
  197. [source, sql]
  198. ----
  199. ROUND(
  200. numeric_exp <1>
  201. [, integer_exp]) <2>
  202. ----
  203. *Input*:
  204. <1> numeric expression. If `null`, the function returns `null`.
  205. <2> integer expression; optional. If `null`, the function returns `null`.
  206. *Output*: numeric
  207. *Description*: Returns `numeric_exp` rounded to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  208. `numeric_exp` is rounded to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  209. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  210. of `numeric_exp`.
  211. ["source","sql",subs="attributes,macros"]
  212. --------------------------------------------------
  213. include-tagged::{sql-specs}/docs/docs.csv-spec[mathRoundWithPositiveParameter]
  214. --------------------------------------------------
  215. ["source","sql",subs="attributes,macros"]
  216. --------------------------------------------------
  217. include-tagged::{sql-specs}/docs/docs.csv-spec[mathRoundWithNegativeParameter]
  218. --------------------------------------------------
  219. [[sql-functions-math-sign]]
  220. ==== `SIGN/SIGNUM`
  221. .Synopsis:
  222. [source, sql]
  223. --------------------------------------------------
  224. SIGN(numeric_exp) <1>
  225. --------------------------------------------------
  226. *Input*:
  227. <1> numeric expression. If `null`, the function returns `null`.
  228. *Output*: [-1, 0, 1]
  229. *Description*: Returns an indicator of the sign of `numeric_exp`. If `numeric_exp` is less than zero, –1 is returned. If `numeric_exp` equals zero, 0 is returned. If `numeric_exp` is greater than zero, 1 is returned.
  230. ["source","sql",subs="attributes,macros"]
  231. --------------------------------------------------
  232. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSign]
  233. --------------------------------------------------
  234. [[sql-functions-math-sqrt]]
  235. ==== `SQRT`
  236. .Synopsis:
  237. [source, sql]
  238. --------------------------------------------------
  239. SQRT(numeric_exp) <1>
  240. --------------------------------------------------
  241. *Input*:
  242. <1> numeric expression. If `null`, the function returns `null`.
  243. *Output*: double numeric value
  244. *Description*: Returns {wikipedia}/Square_root[square root] of `numeric_exp`.
  245. ["source","sql",subs="attributes,macros"]
  246. --------------------------------------------------
  247. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSqrt]
  248. --------------------------------------------------
  249. [[sql-functions-math-truncate]]
  250. ==== `TRUNCATE/TRUNC`
  251. .Synopsis:
  252. [source, sql]
  253. ----
  254. TRUNCATE(
  255. numeric_exp <1>
  256. [, integer_exp]) <2>
  257. ----
  258. *Input*:
  259. <1> numeric expression. If `null`, the function returns `null`.
  260. <2> integer expression; optional. If `null`, the function returns `null`.
  261. *Output*: numeric
  262. *Description*: Returns `numeric_exp` truncated to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  263. `numeric_exp` is truncated to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  264. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  265. of `numeric_exp`.
  266. ["source","sql",subs="attributes,macros"]
  267. --------------------------------------------------
  268. include-tagged::{sql-specs}/docs/docs.csv-spec[mathTruncateWithPositiveParameter]
  269. --------------------------------------------------
  270. ["source","sql",subs="attributes,macros"]
  271. --------------------------------------------------
  272. include-tagged::{sql-specs}/docs/docs.csv-spec[mathTruncateWithNegativeParameter]
  273. --------------------------------------------------
  274. [[sql-functions-math-trigonometric]]
  275. [discrete]
  276. === Trigonometric
  277. [[sql-functions-math-acos]]
  278. ==== `ACOS`
  279. .Synopsis:
  280. [source, sql]
  281. --------------------------------------------------
  282. ACOS(numeric_exp) <1>
  283. --------------------------------------------------
  284. *Input*:
  285. <1> numeric expression. If `null`, the function returns `null`.
  286. *Output*: double numeric value
  287. *Description*: Returns the {wikipedia}/Inverse_trigonometric_functions[arccosine] of `numeric_exp` as an angle, expressed in radians.
  288. ["source","sql",subs="attributes,macros"]
  289. --------------------------------------------------
  290. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAcos]
  291. --------------------------------------------------
  292. [[sql-functions-math-asin]]
  293. ==== `ASIN`
  294. .Synopsis:
  295. [source, sql]
  296. --------------------------------------------------
  297. ASIN(numeric_exp) <1>
  298. --------------------------------------------------
  299. *Input*:
  300. <1> numeric expression. If `null`, the function returns `null`.
  301. *Output*: double numeric value
  302. *Description*: Returns the {wikipedia}/Inverse_trigonometric_functions[arcsine] of `numeric_exp` as an angle, expressed in radians.
  303. ["source","sql",subs="attributes,macros"]
  304. --------------------------------------------------
  305. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAsin]
  306. --------------------------------------------------
  307. [[sql-functions-math-atan]]
  308. ==== `ATAN`
  309. .Synopsis:
  310. [source, sql]
  311. --------------------------------------------------
  312. ATAN(numeric_exp) <1>
  313. --------------------------------------------------
  314. *Input*:
  315. <1> numeric expression. If `null`, the function returns `null`.
  316. *Output*: double numeric value
  317. *Description*: Returns the {wikipedia}/Inverse_trigonometric_functions[arctangent] of `numeric_exp` as an angle, expressed in radians.
  318. ["source","sql",subs="attributes,macros"]
  319. --------------------------------------------------
  320. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAtan]
  321. --------------------------------------------------
  322. [[sql-functions-math-atan2]]
  323. ==== `ATAN2`
  324. .Synopsis:
  325. [source, sql]
  326. --------------------------------------------------
  327. ATAN2(
  328. ordinate, <1>
  329. abscisa) <2>
  330. --------------------------------------------------
  331. *Input*:
  332. <1> numeric expression. If `null`, the function returns `null`.
  333. <2> numeric expression. If `null`, the function returns `null`.
  334. *Output*: double numeric value
  335. *Description*: Returns the {wikipedia}/Atan2[arctangent of the `ordinate` and `abscisa` coordinates] specified as an angle, expressed in radians.
  336. ["source","sql",subs="attributes,macros"]
  337. --------------------------------------------------
  338. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAtan2]
  339. --------------------------------------------------
  340. [[sql-functions-math-cos]]
  341. ==== `COS`
  342. .Synopsis:
  343. [source, sql]
  344. --------------------------------------------------
  345. COS(numeric_exp) <1>
  346. --------------------------------------------------
  347. *Input*:
  348. <1> numeric expression. If `null`, the function returns `null`.
  349. *Output*: double numeric value
  350. *Description*: Returns the {wikipedia}/Trigonometric_functions#cosine[cosine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  351. ["source","sql",subs="attributes,macros"]
  352. --------------------------------------------------
  353. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCosine]
  354. --------------------------------------------------
  355. [[sql-functions-math-cosh]]
  356. ==== `COSH`
  357. .Synopsis:
  358. [source, sql]
  359. --------------------------------------------------
  360. COSH(numeric_exp) <1>
  361. --------------------------------------------------
  362. *Input*:
  363. <1> numeric expression. If `null`, the function returns `null`.
  364. *Output*: double numeric value
  365. *Description*: Returns the {wikipedia}/Hyperbolic_function[hyperbolic cosine] of `numeric_exp`.
  366. ["source","sql",subs="attributes,macros"]
  367. --------------------------------------------------
  368. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCosh]
  369. --------------------------------------------------
  370. [[sql-functions-math-cot]]
  371. ==== `COT`
  372. .Synopsis:
  373. [source, sql]
  374. --------------------------------------------------
  375. COT(numeric_exp) <1>
  376. --------------------------------------------------
  377. *Input*:
  378. <1> numeric expression. If `null`, the function returns `null`.
  379. *Output*: double numeric value
  380. *Description*: Returns the {wikipedia}/Trigonometric_functions#Cosecant,_secant,_and_cotangent[cotangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  381. ["source","sql",subs="attributes,macros"]
  382. --------------------------------------------------
  383. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCotangent]
  384. --------------------------------------------------
  385. [[sql-functions-math-degrees]]
  386. ==== `DEGREES`
  387. .Synopsis:
  388. [source, sql]
  389. --------------------------------------------------
  390. DEGREES(numeric_exp) <1>
  391. --------------------------------------------------
  392. *Input*:
  393. <1> numeric expression. If `null`, the function returns `null`.
  394. *Output*: double numeric value
  395. *Description*: Convert from {wikipedia}/Radian[radians]
  396. to {wikipedia}/Degree_(angle)[degrees].
  397. ["source","sql",subs="attributes,macros"]
  398. --------------------------------------------------
  399. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineDegrees]
  400. --------------------------------------------------
  401. [[sql-functions-math-radians]]
  402. ==== `RADIANS`
  403. .Synopsis:
  404. [source, sql]
  405. --------------------------------------------------
  406. RADIANS(numeric_exp) <1>
  407. --------------------------------------------------
  408. *Input*:
  409. <1> numeric expression. If `null`, the function returns `null`.
  410. *Output*: double numeric value
  411. *Description*: Convert from {wikipedia}/Degree_(angle)[degrees]
  412. to {wikipedia}/Radian[radians].
  413. ["source","sql",subs="attributes,macros"]
  414. --------------------------------------------------
  415. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineRadians]
  416. --------------------------------------------------
  417. [[sql-functions-math-sin]]
  418. ==== `SIN`
  419. .Synopsis:
  420. [source, sql]
  421. --------------------------------------------------
  422. SIN(numeric_exp) <1>
  423. --------------------------------------------------
  424. *Input*:
  425. <1> numeric expression. If `null`, the function returns `null`.
  426. *Output*: double numeric value
  427. *Description*: Returns the {wikipedia}/Trigonometric_functions#sine[sine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  428. ["source","sql",subs="attributes,macros"]
  429. --------------------------------------------------
  430. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSine]
  431. --------------------------------------------------
  432. [[sql-functions-math-sinh]]
  433. ==== `SINH`
  434. .Synopsis:
  435. [source, sql]
  436. --------------------------------------------------
  437. SINH(numeric_exp) <1>
  438. --------------------------------------------------
  439. *Input*:
  440. <1> numeric expression. If `null`, the function returns `null`.
  441. *Output*: double numeric value
  442. *Description*: Returns the {wikipedia}/Hyperbolic_function[hyperbolic sine] of `numeric_exp`.
  443. ["source","sql",subs="attributes,macros"]
  444. --------------------------------------------------
  445. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSinh]
  446. --------------------------------------------------
  447. [[sql-functions-math-tan]]
  448. ==== `TAN`
  449. .Synopsis:
  450. [source, sql]
  451. --------------------------------------------------
  452. TAN(numeric_exp) <1>
  453. --------------------------------------------------
  454. *Input*:
  455. <1> numeric expression. If `null`, the function returns `null`.
  456. *Output*: double numeric value
  457. *Description*: Returns the {wikipedia}/Trigonometric_functions#tangent[tangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  458. ["source","sql",subs="attributes,macros"]
  459. --------------------------------------------------
  460. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineTanget]
  461. --------------------------------------------------