string.asciidoc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-functions-string]]
  4. === String Functions
  5. Functions for performing string manipulation.
  6. [[sql-functions-string-ascii]]
  7. ==== `ASCII`
  8. .Synopsis:
  9. [source, sql]
  10. --------------------------------------------------
  11. ASCII(string_exp) <1>
  12. --------------------------------------------------
  13. *Input*:
  14. <1> string expression. If `null`, the function returns `null`.
  15. *Output*: integer
  16. *Description*: Returns the ASCII code value of the leftmost character of `string_exp` as an integer.
  17. [source, sql]
  18. --------------------------------------------------
  19. include-tagged::{sql-specs}/docs/docs.csv-spec[stringAscii]
  20. --------------------------------------------------
  21. [[sql-functions-string-bit-length]]
  22. ==== `BIT_LENGTH`
  23. .Synopsis:
  24. [source, sql]
  25. --------------------------------------------------
  26. BIT_LENGTH(string_exp) <1>
  27. --------------------------------------------------
  28. *Input*:
  29. <1> string expression. If `null`, the function returns `null`.
  30. *Output*: integer
  31. *Description*: Returns the length in bits of the `string_exp` input expression.
  32. [source, sql]
  33. --------------------------------------------------
  34. include-tagged::{sql-specs}/docs/docs.csv-spec[stringBitLength]
  35. --------------------------------------------------
  36. [[sql-functions-string-char]]
  37. ==== `CHAR`
  38. .Synopsis:
  39. [source, sql]
  40. --------------------------------------------------
  41. CHAR(code) <1>
  42. --------------------------------------------------
  43. *Input*:
  44. <1> integer expression between `0` and `255`. If `null`, negative, or greater
  45. than `255`, the function returns `null`.
  46. *Output*: string
  47. *Description*: Returns the character that has the ASCII code value specified by the numeric input.
  48. [source, sql]
  49. --------------------------------------------------
  50. include-tagged::{sql-specs}/docs/docs.csv-spec[stringChar]
  51. --------------------------------------------------
  52. [[sql-functions-string-char-length]]
  53. ==== `CHAR_LENGTH`
  54. .Synopsis:
  55. [source, sql]
  56. --------------------------------------------------
  57. CHAR_LENGTH(string_exp) <1>
  58. --------------------------------------------------
  59. *Input*:
  60. <1> string expression. If `null`, the function returns `null`.
  61. *Output*: integer
  62. *Description*: Returns the length in characters of the input, if the string expression is of a character data type; otherwise, returns the length in bytes of the string expression (the smallest integer not less than the number of bits divided by 8).
  63. [source, sql]
  64. --------------------------------------------------
  65. include-tagged::{sql-specs}/docs/docs.csv-spec[stringCharLength]
  66. --------------------------------------------------
  67. [[sql-functions-string-concat]]
  68. ==== `CONCAT`
  69. .Synopsis:
  70. [source, sql]
  71. --------------------------------------------------
  72. CONCAT(
  73. string_exp1, <1>
  74. string_exp2) <2>
  75. --------------------------------------------------
  76. *Input*:
  77. <1> string expression. Treats `null` as an empty string.
  78. <2> string expression. Treats `null` as an empty string.
  79. *Output*: string
  80. *Description*: Returns a character string that is the result of concatenating `string_exp1` to `string_exp2`.
  81. [source, sql]
  82. --------------------------------------------------
  83. include-tagged::{sql-specs}/docs/docs.csv-spec[stringConcat]
  84. --------------------------------------------------
  85. [[sql-functions-string-insert]]
  86. ==== `INSERT`
  87. .Synopsis:
  88. [source, sql]
  89. --------------------------------------------------
  90. INSERT(
  91. source, <1>
  92. start, <2>
  93. length, <3>
  94. replacement) <4>
  95. --------------------------------------------------
  96. *Input*:
  97. <1> string expression. If `null`, the function returns `null`.
  98. <2> integer expression. If `null`, the function returns `null`.
  99. <3> integer expression. If `null`, the function returns `null`.
  100. <4> string expression. If `null`, the function returns `null`.
  101. *Output*: string
  102. *Description*: Returns a string where `length` characters have been deleted from `source`, beginning at `start`, and where `replacement` has been inserted into `source`, beginning at `start`.
  103. [source, sql]
  104. --------------------------------------------------
  105. include-tagged::{sql-specs}/docs/docs.csv-spec[stringInsert]
  106. --------------------------------------------------
  107. [[sql-functions-string-lcase]]
  108. ==== `LCASE`
  109. .Synopsis:
  110. [source, sql]
  111. --------------------------------------------------
  112. LCASE(string_exp) <1>
  113. --------------------------------------------------
  114. *Input*:
  115. <1> string expression. If `null`, the function returns `null`.
  116. *Output*: string
  117. *Description*: Returns a string equal to that in `string_exp`, with all uppercase characters converted to lowercase.
  118. [source, sql]
  119. --------------------------------------------------
  120. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLCase]
  121. --------------------------------------------------
  122. [[sql-functions-string-left]]
  123. ==== `LEFT`
  124. .Synopsis:
  125. [source, sql]
  126. --------------------------------------------------
  127. LEFT(
  128. string_exp, <1>
  129. count) <2>
  130. --------------------------------------------------
  131. *Input*:
  132. <1> string expression. If `null`, the function returns `null`.
  133. <2> integer expression. If `null`, the function returns `null`. If `0` or
  134. negative, the function returns an empty string.
  135. *Output*: string
  136. *Description*: Returns the leftmost count characters of `string_exp`.
  137. [source, sql]
  138. --------------------------------------------------
  139. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLeft]
  140. --------------------------------------------------
  141. [[sql-functions-string-length]]
  142. ==== `LENGTH`
  143. .Synopsis:
  144. [source, sql]
  145. --------------------------------------------------
  146. LENGTH(string_exp) <1>
  147. --------------------------------------------------
  148. *Input*:
  149. <1> string expression. If `null`, the function returns `null`.
  150. *Output*: integer
  151. *Description*: Returns the number of characters in `string_exp`, excluding trailing blanks.
  152. [source, sql]
  153. --------------------------------------------------
  154. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLength]
  155. --------------------------------------------------
  156. [[sql-functions-string-locate]]
  157. ==== `LOCATE`
  158. .Synopsis:
  159. [source, sql]
  160. --------------------------------------------------
  161. LOCATE(
  162. pattern, <1>
  163. source <2>
  164. [, start]<3>
  165. )
  166. --------------------------------------------------
  167. *Input*:
  168. <1> string expression. If `null`, the function returns `null`.
  169. <2> string expression. If `null`, the function returns `null`.
  170. <3> integer expression; optional. If `null`, `0`, `1`, negative, or not
  171. specified, the search starts at the first character position.
  172. *Output*: integer
  173. *Description*: Returns the starting position of the first occurrence of
  174. `pattern` within `source`. The optional `start` specifies the character position
  175. to start the search with. If the `pattern` is not found within `source`, the
  176. function returns `0`.
  177. [source, sql]
  178. --------------------------------------------------
  179. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLocateWoStart]
  180. --------------------------------------------------
  181. [source, sql]
  182. --------------------------------------------------
  183. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLocateWithStart]
  184. --------------------------------------------------
  185. [[sql-functions-string-ltrim]]
  186. ==== `LTRIM`
  187. .Synopsis:
  188. [source, sql]
  189. --------------------------------------------------
  190. LTRIM(string_exp) <1>
  191. --------------------------------------------------
  192. *Input*:
  193. <1> string expression. If `null`, the function returns `null`.
  194. *Output*: string
  195. *Description*: Returns the characters of `string_exp`, with leading blanks removed.
  196. [source, sql]
  197. --------------------------------------------------
  198. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLTrim]
  199. --------------------------------------------------
  200. [[sql-functions-string-octet-length]]
  201. ==== `OCTET_LENGTH`
  202. .Synopsis:
  203. [source, sql]
  204. --------------------------------------------------
  205. OCTET_LENGTH(string_exp) <1>
  206. --------------------------------------------------
  207. *Input*:
  208. <1> string expression. If `null`, the function returns `null`.
  209. *Output*: integer
  210. *Description*: Returns the length in bytes of the `string_exp` input expression.
  211. [source, sql]
  212. --------------------------------------------------
  213. include-tagged::{sql-specs}/docs/docs.csv-spec[stringOctetLength]
  214. --------------------------------------------------
  215. [[sql-functions-string-position]]
  216. ==== `POSITION`
  217. .Synopsis:
  218. [source, sql]
  219. --------------------------------------------------
  220. POSITION(
  221. string_exp1, <1>
  222. string_exp2) <2>
  223. --------------------------------------------------
  224. *Input*:
  225. <1> string expression. If `null`, the function returns `null`.
  226. <2> string expression. If `null`, the function returns `null`.
  227. *Output*: integer
  228. *Description*: Returns the position of the `string_exp1` in `string_exp2`. The result is an exact numeric.
  229. [source, sql]
  230. --------------------------------------------------
  231. include-tagged::{sql-specs}/docs/docs.csv-spec[stringPosition]
  232. --------------------------------------------------
  233. [[sql-functions-string-repeat]]
  234. ==== `REPEAT`
  235. .Synopsis:
  236. [source, sql]
  237. --------------------------------------------------
  238. REPEAT(
  239. string_exp, <1>
  240. count) <2>
  241. --------------------------------------------------
  242. *Input*:
  243. <1> string expression. If `null`, the function returns `null`.
  244. <2> integer expression. If `0`, negative, or `null`, the function returns `null`.
  245. *Output*: string
  246. *Description*: Returns a character string composed of `string_exp` repeated `count` times.
  247. [source, sql]
  248. --------------------------------------------------
  249. include-tagged::{sql-specs}/docs/docs.csv-spec[stringRepeat]
  250. --------------------------------------------------
  251. [[sql-functions-string-replace]]
  252. ==== `REPLACE`
  253. .Synopsis:
  254. [source, sql]
  255. --------------------------------------------------
  256. REPLACE(
  257. source, <1>
  258. pattern, <2>
  259. replacement) <3>
  260. --------------------------------------------------
  261. *Input*:
  262. <1> string expression. If `null`, the function returns `null`.
  263. <2> string expression. If `null`, the function returns `null`.
  264. <3> string expression. If `null`, the function returns `null`.
  265. *Output*: string
  266. *Description*: Search `source` for occurrences of `pattern`, and replace with `replacement`.
  267. [source, sql]
  268. --------------------------------------------------
  269. include-tagged::{sql-specs}/docs/docs.csv-spec[stringReplace]
  270. --------------------------------------------------
  271. [[sql-functions-string-right]]
  272. ==== `RIGHT`
  273. .Synopsis:
  274. [source, sql]
  275. --------------------------------------------------
  276. RIGHT(
  277. string_exp, <1>
  278. count) <2>
  279. --------------------------------------------------
  280. *Input*:
  281. <1> string expression. If `null`, the function returns `null`.
  282. <2> integer expression. If `null`, the function returns `null`. If `0` or
  283. negative, the function returns an empty string.
  284. *Output*: string
  285. *Description*: Returns the rightmost count characters of `string_exp`.
  286. [source, sql]
  287. --------------------------------------------------
  288. include-tagged::{sql-specs}/docs/docs.csv-spec[stringRight]
  289. --------------------------------------------------
  290. [[sql-functions-string-rtrim]]
  291. ==== `RTRIM`
  292. .Synopsis:
  293. [source, sql]
  294. --------------------------------------------------
  295. RTRIM(string_exp) <1>
  296. --------------------------------------------------
  297. *Input*:
  298. <1> string expression. If `null`, the function returns `null`.
  299. *Output*: string
  300. *Description*: Returns the characters of `string_exp` with trailing blanks removed.
  301. [source, sql]
  302. --------------------------------------------------
  303. include-tagged::{sql-specs}/docs/docs.csv-spec[stringRTrim]
  304. --------------------------------------------------
  305. [[sql-functions-string-space]]
  306. ==== `SPACE`
  307. .Synopsis:
  308. [source, sql]
  309. --------------------------------------------------
  310. SPACE(count) <1>
  311. --------------------------------------------------
  312. *Input*:
  313. <1> integer expression. If `null` or negative, the function returns `null`.
  314. *Output*: string
  315. *Description*: Returns a character string consisting of `count` spaces.
  316. [source, sql]
  317. --------------------------------------------------
  318. include-tagged::{sql-specs}/docs/docs.csv-spec[stringSpace]
  319. --------------------------------------------------
  320. [[sql-functions-string-startswith]]
  321. ==== `STARTS_WITH`
  322. .Synopsis:
  323. [source, sql]
  324. --------------------------------------------------
  325. STARTS_WITH(
  326. source, <1>
  327. pattern) <2>
  328. --------------------------------------------------
  329. *Input*:
  330. <1> string expression. If `null`, the function returns `null`.
  331. <2> string expression. If `null`, the function returns `null`.
  332. *Output*: boolean value
  333. *Description*: Returns `true` if the source expression starts with the specified
  334. pattern, `false` otherwise. The matching is case sensitive.
  335. [source, sql]
  336. --------------------------------------------------
  337. include-tagged::{sql-specs}/docs/docs.csv-spec[stringStartsWithTrue]
  338. --------------------------------------------------
  339. [source, sql]
  340. --------------------------------------------------
  341. include-tagged::{sql-specs}/docs/docs.csv-spec[stringStartsWithFalse]
  342. --------------------------------------------------
  343. [[sql-functions-string-substring]]
  344. ==== `SUBSTRING`
  345. .Synopsis:
  346. [source, sql]
  347. --------------------------------------------------
  348. SUBSTRING(
  349. source, <1>
  350. start, <2>
  351. length) <3>
  352. --------------------------------------------------
  353. *Input*:
  354. <1> string expression. If `null`, the function returns `null`.
  355. <2> integer expression. If `null`, the function returns `null`.
  356. <3> integer expression. If `null`, the function returns `null`.
  357. *Output*: string
  358. *Description*: Returns a character string that is derived from `source`, beginning at the character position specified by `start` for `length` characters.
  359. [source, sql]
  360. --------------------------------------------------
  361. include-tagged::{sql-specs}/docs/docs.csv-spec[stringSubString]
  362. --------------------------------------------------
  363. [[sql-functions-string-trim]]
  364. ==== `TRIM`
  365. .Synopsis:
  366. [source, sql]
  367. --------------------------------------------------
  368. TRIM(string_exp) <1>
  369. --------------------------------------------------
  370. *Input*:
  371. <1> string expression. If `null`, the function returns `null`.
  372. *Output*: string
  373. *Description*: Returns the characters of `string_exp`, with leading and trailing blanks removed.
  374. [source, sql]
  375. --------------------------------------------------
  376. include-tagged::{sql-specs}/docs/docs.csv-spec[stringTrim]
  377. --------------------------------------------------
  378. [[sql-functions-string-ucase]]
  379. ==== `UCASE`
  380. .Synopsis:
  381. [source, sql]
  382. --------------------------------------------------
  383. UCASE(string_exp) <1>
  384. --------------------------------------------------
  385. *Input*:
  386. <1> string expression. If `null`, the function returns `null`.
  387. *Output*: string
  388. *Description*: Returns a string equal to that of the input, with all lowercase characters converted to uppercase.
  389. [source, sql]
  390. --------------------------------------------------
  391. include-tagged::{sql-specs}/docs/docs.csv-spec[stringUCase]
  392. --------------------------------------------------