string.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-functions-string]]
  4. === String Functions
  5. beta[]
  6. Functions for performing string manipulation.
  7. [[sql-functions-string-ascii]]
  8. ==== `ASCII`
  9. .Synopsis:
  10. [source, sql]
  11. --------------------------------------------------
  12. ASCII(string_exp<1>)
  13. --------------------------------------------------
  14. *Input*:
  15. <1> string expression
  16. *Output*: integer
  17. .Description:
  18. Returns the ASCII code value of the leftmost character of `string_exp` as an integer.
  19. ["source","sql",subs="attributes,callouts,macros"]
  20. --------------------------------------------------
  21. include-tagged::{sql-specs}/docs.csv-spec[stringAscii]
  22. --------------------------------------------------
  23. [[sql-functions-string-bit-length]]
  24. ==== `BIT_LENGTH`
  25. .Synopsis:
  26. [source, sql]
  27. --------------------------------------------------
  28. BIT_LENGTH(string_exp<1>)
  29. --------------------------------------------------
  30. *Input*:
  31. <1> string expression
  32. *Output*: integer
  33. .Description:
  34. Returns the length in bits of the `string_exp` input expression.
  35. ["source","sql",subs="attributes,callouts,macros"]
  36. --------------------------------------------------
  37. include-tagged::{sql-specs}/docs.csv-spec[stringBitLength]
  38. --------------------------------------------------
  39. [[sql-functions-string-char]]
  40. ==== `CHAR`
  41. .Synopsis:
  42. [source, sql]
  43. --------------------------------------------------
  44. CHAR(code<1>)
  45. --------------------------------------------------
  46. *Input*:
  47. <1> integer expression
  48. *Output*: string
  49. .Description:
  50. 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.
  51. ["source","sql",subs="attributes,callouts,macros"]
  52. --------------------------------------------------
  53. include-tagged::{sql-specs}/docs.csv-spec[stringChar]
  54. --------------------------------------------------
  55. [[sql-functions-string-char-length]]
  56. ==== `CHAR_LENGTH`
  57. .Synopsis:
  58. [source, sql]
  59. --------------------------------------------------
  60. CHAR_LENGTH(string_exp<1>)
  61. --------------------------------------------------
  62. *Input*:
  63. <1> string expression
  64. *Output*: integer
  65. .Description:
  66. 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).
  67. ["source","sql",subs="attributes,callouts,macros"]
  68. --------------------------------------------------
  69. include-tagged::{sql-specs}/docs.csv-spec[stringCharLength]
  70. --------------------------------------------------
  71. [[sql-functions-string-concat]]
  72. ==== `CONCAT`
  73. .Synopsis:
  74. [source, sql]
  75. --------------------------------------------------
  76. CONCAT(string_exp1<1>,string_exp2<2>)
  77. --------------------------------------------------
  78. *Input*:
  79. <1> string expression
  80. <2> string expression
  81. *Output*: string
  82. .Description:
  83. 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.
  84. ["source","sql",subs="attributes,callouts,macros"]
  85. --------------------------------------------------
  86. include-tagged::{sql-specs}/docs.csv-spec[stringConcat]
  87. --------------------------------------------------
  88. [[sql-functions-string-insert]]
  89. ==== `INSERT`
  90. .Synopsis:
  91. [source, sql]
  92. --------------------------------------------------
  93. INSERT(source<1>, start<2>, length<3>, 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:
  102. 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",subs="attributes,callouts,macros"]
  104. --------------------------------------------------
  105. include-tagged::{sql-specs}/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
  116. *Output*: string
  117. .Description:
  118. Returns a string equal to that in `string_exp`, with all uppercase characters converted to lowercase.
  119. ["source","sql",subs="attributes,callouts,macros"]
  120. --------------------------------------------------
  121. include-tagged::{sql-specs}/docs.csv-spec[stringLCase]
  122. --------------------------------------------------
  123. [[sql-functions-string-left]]
  124. ==== `LEFT`
  125. .Synopsis:
  126. [source, sql]
  127. --------------------------------------------------
  128. LEFT(string_exp<1>, count<2>)
  129. --------------------------------------------------
  130. *Input*:
  131. <1> string expression
  132. <2> integer expression
  133. *Output*: string
  134. .Description:
  135. Returns the leftmost count characters of `string_exp`.
  136. ["source","sql",subs="attributes,callouts,macros"]
  137. --------------------------------------------------
  138. include-tagged::{sql-specs}/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
  149. *Output*: integer
  150. .Description:
  151. Returns the number of characters in `string_exp`, excluding trailing blanks.
  152. ["source","sql",subs="attributes,callouts,macros"]
  153. --------------------------------------------------
  154. include-tagged::{sql-specs}/docs.csv-spec[stringLength]
  155. --------------------------------------------------
  156. [[sql-functions-string-locate]]
  157. ==== `LOCATE`
  158. .Synopsis:
  159. [source, sql]
  160. --------------------------------------------------
  161. LOCATE(pattern<1>, source<2>[, start]<3>)
  162. --------------------------------------------------
  163. *Input*:
  164. <1> string expression
  165. <2> string expression
  166. <3> integer expression; optional
  167. *Output*: integer
  168. .Description:
  169. 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.
  170. ["source","sql",subs="attributes,callouts,macros"]
  171. --------------------------------------------------
  172. include-tagged::{sql-specs}/docs.csv-spec[stringLocateWoStart]
  173. --------------------------------------------------
  174. ["source","sql",subs="attributes,callouts,macros"]
  175. --------------------------------------------------
  176. include-tagged::{sql-specs}/docs.csv-spec[stringLocateWithStart]
  177. --------------------------------------------------
  178. [[sql-functions-string-ltrim]]
  179. ==== `LTRIM`
  180. .Synopsis:
  181. [source, sql]
  182. --------------------------------------------------
  183. LTRIM(string_exp<1>)
  184. --------------------------------------------------
  185. *Input*:
  186. <1> string expression
  187. *Output*: string
  188. .Description:
  189. Returns the characters of `string_exp`, with leading blanks removed.
  190. ["source","sql",subs="attributes,callouts,macros"]
  191. --------------------------------------------------
  192. include-tagged::{sql-specs}/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:
  205. Returns the length in bytes of the `string_exp` input expression.
  206. ["source","sql",subs="attributes,callouts,macros"]
  207. --------------------------------------------------
  208. include-tagged::{sql-specs}/docs.csv-spec[stringOctetLength]
  209. --------------------------------------------------
  210. [[sql-functions-string-position]]
  211. ==== `POSITION`
  212. .Synopsis:
  213. [source, sql]
  214. --------------------------------------------------
  215. POSITION(string_exp1<1>, string_exp2<2>)
  216. --------------------------------------------------
  217. *Input*:
  218. <1> string expression
  219. <2> string expression
  220. *Output*: integer
  221. .Description:
  222. Returns the position of the `string_exp1` in `string_exp2`. The result is an exact numeric.
  223. ["source","sql",subs="attributes,callouts,macros"]
  224. --------------------------------------------------
  225. include-tagged::{sql-specs}/docs.csv-spec[stringPosition]
  226. --------------------------------------------------
  227. [[sql-functions-string-repeat]]
  228. ==== `REPEAT`
  229. .Synopsis:
  230. [source, sql]
  231. --------------------------------------------------
  232. REPEAT(string_exp<1>, count<2>)
  233. --------------------------------------------------
  234. *Input*:
  235. <1> string expression
  236. <2> integer expression
  237. *Output*: string
  238. .Description:
  239. Returns a character string composed of `string_exp` repeated `count` times.
  240. ["source","sql",subs="attributes,callouts,macros"]
  241. --------------------------------------------------
  242. include-tagged::{sql-specs}/docs.csv-spec[stringRepeat]
  243. --------------------------------------------------
  244. [[sql-functions-string-replace]]
  245. ==== `REPLACE`
  246. .Synopsis:
  247. [source, sql]
  248. --------------------------------------------------
  249. REPLACE(source<1>, pattern<2>, replacement<3>)
  250. --------------------------------------------------
  251. *Input*:
  252. <1> string expression
  253. <2> string expression
  254. <3> string expression
  255. *Output*: string
  256. .Description:
  257. Search `source` for occurrences of `pattern`, and replace with `replacement`.
  258. ["source","sql",subs="attributes,callouts,macros"]
  259. --------------------------------------------------
  260. include-tagged::{sql-specs}/docs.csv-spec[stringReplace]
  261. --------------------------------------------------
  262. [[sql-functions-string-right]]
  263. ==== `RIGHT`
  264. .Synopsis:
  265. [source, sql]
  266. --------------------------------------------------
  267. RIGHT(string_exp<1>, count<2>)
  268. --------------------------------------------------
  269. *Input*:
  270. <1> string expression
  271. <2> integer expression
  272. *Output*: string
  273. .Description:
  274. Returns the rightmost count characters of `string_exp`.
  275. ["source","sql",subs="attributes,callouts,macros"]
  276. --------------------------------------------------
  277. include-tagged::{sql-specs}/docs.csv-spec[stringRight]
  278. --------------------------------------------------
  279. [[sql-functions-string-rtrim]]
  280. ==== `RTRIM`
  281. .Synopsis:
  282. [source, sql]
  283. --------------------------------------------------
  284. RTRIM(string_exp<1>)
  285. --------------------------------------------------
  286. *Input*:
  287. <1> string expression
  288. *Output*: string
  289. .Description:
  290. Returns the characters of `string_exp` with trailing blanks removed.
  291. ["source","sql",subs="attributes,callouts,macros"]
  292. --------------------------------------------------
  293. include-tagged::{sql-specs}/docs.csv-spec[stringRTrim]
  294. --------------------------------------------------
  295. [[sql-functions-string-space]]
  296. ==== `SPACE`
  297. .Synopsis:
  298. [source, sql]
  299. --------------------------------------------------
  300. SPACE(count<1>)
  301. --------------------------------------------------
  302. *Input*:
  303. <1> integer expression
  304. *Output*: string
  305. .Description:
  306. Returns a character string consisting of `count` spaces.
  307. ["source","sql",subs="attributes,callouts,macros"]
  308. --------------------------------------------------
  309. include-tagged::{sql-specs}/docs.csv-spec[stringSpace]
  310. --------------------------------------------------
  311. [[sql-functions-string-substring]]
  312. ==== `SUBSTRING`
  313. .Synopsis:
  314. [source, sql]
  315. --------------------------------------------------
  316. SUBSTRING(source<1>, start<2>, length<3>)
  317. --------------------------------------------------
  318. *Input*:
  319. <1> string expression
  320. <2> integer expression
  321. <3> integer expression
  322. *Output*: string
  323. .Description:
  324. Returns a character string that is derived from `source`, beginning at the character position specified by `start` for `length` characters.
  325. ["source","sql",subs="attributes,callouts,macros"]
  326. --------------------------------------------------
  327. include-tagged::{sql-specs}/docs.csv-spec[stringSubString]
  328. --------------------------------------------------
  329. [[sql-functions-string-ucase]]
  330. ==== `UCASE`
  331. .Synopsis:
  332. [source, sql]
  333. --------------------------------------------------
  334. UCASE(string_exp<1>)
  335. --------------------------------------------------
  336. *Input*:
  337. <1> string expression
  338. *Output*: string
  339. .Description:
  340. Returns a string equal to that of the input, with all lowercase characters converted to uppercase.
  341. ["source","sql",subs="attributes,callouts,macros"]
  342. --------------------------------------------------
  343. include-tagged::{sql-specs}/docs.csv-spec[stringUCase]
  344. --------------------------------------------------