string.asciidoc 12 KB

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