string.asciidoc 15 KB

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