string.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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
  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
  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
  45. *Output*: string
  46. *Description*: Returns the character that has the ASCII code value specified by the numeric input. The value should be between 0 and 255; otherwise, the return value is data source–dependent.
  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
  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
  77. <2> string expression
  78. *Output*: string
  79. *Description*: Returns a character string that is the result of concatenating `string_exp1` to `string_exp2`. `NULL` input strings are treated as empty strings.
  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
  97. <2> integer expression
  98. <3> integer expression
  99. <4> string expression
  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
  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
  132. <2> integer expression
  133. *Output*: string
  134. *Description*: Returns the leftmost count characters of `string_exp`.
  135. [source, sql]
  136. --------------------------------------------------
  137. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLeft]
  138. --------------------------------------------------
  139. [[sql-functions-string-length]]
  140. ==== `LENGTH`
  141. .Synopsis:
  142. [source, sql]
  143. --------------------------------------------------
  144. LENGTH(string_exp) <1>
  145. --------------------------------------------------
  146. *Input*:
  147. <1> string expression
  148. *Output*: integer
  149. *Description*: Returns the number of characters in `string_exp`, excluding trailing blanks.
  150. [source, sql]
  151. --------------------------------------------------
  152. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLength]
  153. --------------------------------------------------
  154. [[sql-functions-string-locate]]
  155. ==== `LOCATE`
  156. .Synopsis:
  157. [source, sql]
  158. --------------------------------------------------
  159. LOCATE(
  160. pattern, <1>
  161. source <2>
  162. [, start]<3>
  163. )
  164. --------------------------------------------------
  165. *Input*:
  166. <1> string expression
  167. <2> string expression
  168. <3> integer expression; optional
  169. *Output*: integer
  170. *Description*: Returns the starting position of the first occurrence of `pattern` within `source`. The optional `start` specifies the character position to start the search with. The first character position in `source` is indicated by the value 1. Not specifying `start` or specifying it as `NULL`, any negative value, 0 or 1, starts the search at the first character position. If `pattern` is not found within `source`, the value 0 is returned.
  171. [source, sql]
  172. --------------------------------------------------
  173. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLocateWoStart]
  174. --------------------------------------------------
  175. [source, sql]
  176. --------------------------------------------------
  177. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLocateWithStart]
  178. --------------------------------------------------
  179. [[sql-functions-string-ltrim]]
  180. ==== `LTRIM`
  181. .Synopsis:
  182. [source, sql]
  183. --------------------------------------------------
  184. LTRIM(string_exp) <1>
  185. --------------------------------------------------
  186. *Input*:
  187. <1> string expression
  188. *Output*: string
  189. *Description*: Returns the characters of `string_exp`, with leading blanks removed.
  190. [source, sql]
  191. --------------------------------------------------
  192. include-tagged::{sql-specs}/docs/docs.csv-spec[stringLTrim]
  193. --------------------------------------------------
  194. [[sql-functions-string-octet-length]]
  195. ==== `OCTET_LENGTH`
  196. .Synopsis:
  197. [source, sql]
  198. --------------------------------------------------
  199. OCTET_LENGTH(string_exp) <1>
  200. --------------------------------------------------
  201. *Input*:
  202. <1> string expression
  203. *Output*: integer
  204. *Description*: Returns the length in bytes of the `string_exp` input expression.
  205. [source, sql]
  206. --------------------------------------------------
  207. include-tagged::{sql-specs}/docs/docs.csv-spec[stringOctetLength]
  208. --------------------------------------------------
  209. [[sql-functions-string-position]]
  210. ==== `POSITION`
  211. .Synopsis:
  212. [source, sql]
  213. --------------------------------------------------
  214. POSITION(
  215. string_exp1, <1>
  216. string_exp2) <2>
  217. --------------------------------------------------
  218. *Input*:
  219. <1> string expression
  220. <2> string expression
  221. *Output*: integer
  222. *Description*: Returns the position of the `string_exp1` in `string_exp2`. The result is an exact numeric.
  223. [source, sql]
  224. --------------------------------------------------
  225. include-tagged::{sql-specs}/docs/docs.csv-spec[stringPosition]
  226. --------------------------------------------------
  227. [[sql-functions-string-repeat]]
  228. ==== `REPEAT`
  229. .Synopsis:
  230. [source, sql]
  231. --------------------------------------------------
  232. REPEAT(
  233. string_exp, <1>
  234. count) <2>
  235. --------------------------------------------------
  236. *Input*:
  237. <1> string expression
  238. <2> integer expression
  239. *Output*: string
  240. *Description*: Returns a character string composed of `string_exp` repeated `count` times.
  241. [source, sql]
  242. --------------------------------------------------
  243. include-tagged::{sql-specs}/docs/docs.csv-spec[stringRepeat]
  244. --------------------------------------------------
  245. [[sql-functions-string-replace]]
  246. ==== `REPLACE`
  247. .Synopsis:
  248. [source, sql]
  249. --------------------------------------------------
  250. REPLACE(
  251. source, <1>
  252. pattern, <2>
  253. replacement) <3>
  254. --------------------------------------------------
  255. *Input*:
  256. <1> string expression
  257. <2> string expression
  258. <3> string expression
  259. *Output*: string
  260. *Description*: Search `source` for occurrences of `pattern`, and replace with `replacement`.
  261. [source, sql]
  262. --------------------------------------------------
  263. include-tagged::{sql-specs}/docs/docs.csv-spec[stringReplace]
  264. --------------------------------------------------
  265. [[sql-functions-string-right]]
  266. ==== `RIGHT`
  267. .Synopsis:
  268. [source, sql]
  269. --------------------------------------------------
  270. RIGHT(
  271. string_exp, <1>
  272. count) <2>
  273. --------------------------------------------------
  274. *Input*:
  275. <1> string expression
  276. <2> integer expression
  277. *Output*: string
  278. *Description*: Returns the rightmost count characters of `string_exp`.
  279. [source, sql]
  280. --------------------------------------------------
  281. include-tagged::{sql-specs}/docs/docs.csv-spec[stringRight]
  282. --------------------------------------------------
  283. [[sql-functions-string-rtrim]]
  284. ==== `RTRIM`
  285. .Synopsis:
  286. [source, sql]
  287. --------------------------------------------------
  288. RTRIM(string_exp) <1>
  289. --------------------------------------------------
  290. *Input*:
  291. <1> string expression
  292. *Output*: string
  293. *Description*: Returns the characters of `string_exp` with trailing blanks removed.
  294. [source, sql]
  295. --------------------------------------------------
  296. include-tagged::{sql-specs}/docs/docs.csv-spec[stringRTrim]
  297. --------------------------------------------------
  298. [[sql-functions-string-space]]
  299. ==== `SPACE`
  300. .Synopsis:
  301. [source, sql]
  302. --------------------------------------------------
  303. SPACE(count) <1>
  304. --------------------------------------------------
  305. *Input*:
  306. <1> integer expression
  307. *Output*: string
  308. *Description*: Returns a character string consisting of `count` spaces.
  309. [source, sql]
  310. --------------------------------------------------
  311. include-tagged::{sql-specs}/docs/docs.csv-spec[stringSpace]
  312. --------------------------------------------------
  313. [[sql-functions-string-startswith]]
  314. ==== `STARTS_WITH`
  315. .Synopsis:
  316. [source, sql]
  317. --------------------------------------------------
  318. STARTS_WITH(
  319. source, <1>
  320. pattern) <2>
  321. --------------------------------------------------
  322. *Input*:
  323. <1> string expression
  324. <2> string expression
  325. *Output*: boolean value
  326. *Description*: Returns `true` if the source expression starts with the specified pattern, `false` otherwise. The matching is case sensitive.
  327. If either parameters is `null`, the function returns `null`.
  328. [source, sql]
  329. --------------------------------------------------
  330. include-tagged::{sql-specs}/docs/docs.csv-spec[stringStartsWithTrue]
  331. --------------------------------------------------
  332. [source, sql]
  333. --------------------------------------------------
  334. include-tagged::{sql-specs}/docs/docs.csv-spec[stringStartsWithFalse]
  335. --------------------------------------------------
  336. [[sql-functions-string-substring]]
  337. ==== `SUBSTRING`
  338. .Synopsis:
  339. [source, sql]
  340. --------------------------------------------------
  341. SUBSTRING(
  342. source, <1>
  343. start, <2>
  344. length) <3>
  345. --------------------------------------------------
  346. *Input*:
  347. <1> string expression
  348. <2> integer expression
  349. <3> integer expression
  350. *Output*: string
  351. *Description*: Returns a character string that is derived from `source`, beginning at the character position specified by `start` for `length` characters.
  352. [source, sql]
  353. --------------------------------------------------
  354. include-tagged::{sql-specs}/docs/docs.csv-spec[stringSubString]
  355. --------------------------------------------------
  356. [[sql-functions-string-trim]]
  357. ==== `TRIM`
  358. .Synopsis:
  359. [source, sql]
  360. --------------------------------------------------
  361. TRIM(string_exp) <1>
  362. --------------------------------------------------
  363. *Input*:
  364. <1> string expression
  365. *Output*: string
  366. *Description*: Returns the characters of `string_exp`, with leading and trailing blanks removed.
  367. [source, sql]
  368. --------------------------------------------------
  369. include-tagged::{sql-specs}/docs/docs.csv-spec[stringTrim]
  370. --------------------------------------------------
  371. [[sql-functions-string-ucase]]
  372. ==== `UCASE`
  373. .Synopsis:
  374. [source, sql]
  375. --------------------------------------------------
  376. UCASE(string_exp) <1>
  377. --------------------------------------------------
  378. *Input*:
  379. <1> string expression
  380. *Output*: string
  381. *Description*: Returns a string equal to that of the input, with all lowercase characters converted to uppercase.
  382. [source, sql]
  383. --------------------------------------------------
  384. include-tagged::{sql-specs}/docs/docs.csv-spec[stringUCase]
  385. --------------------------------------------------