string.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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",subs="attributes,callouts,macros"]
  19. --------------------------------------------------
  20. include-tagged::{sql-specs}/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",subs="attributes,callouts,macros"]
  35. --------------------------------------------------
  36. include-tagged::{sql-specs}/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",subs="attributes,callouts,macros"]
  51. --------------------------------------------------
  52. include-tagged::{sql-specs}/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",subs="attributes,callouts,macros"]
  67. --------------------------------------------------
  68. include-tagged::{sql-specs}/docs.csv-spec[stringCharLength]
  69. --------------------------------------------------
  70. [[sql-functions-string-concat]]
  71. ==== `CONCAT`
  72. .Synopsis:
  73. [source, sql]
  74. --------------------------------------------------
  75. CONCAT(string_exp1<1>,string_exp2<2>)
  76. --------------------------------------------------
  77. *Input*:
  78. <1> string expression
  79. <2> string expression
  80. *Output*: string
  81. .Description:
  82. 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.
  83. ["source","sql",subs="attributes,callouts,macros"]
  84. --------------------------------------------------
  85. include-tagged::{sql-specs}/docs.csv-spec[stringConcat]
  86. --------------------------------------------------
  87. [[sql-functions-string-insert]]
  88. ==== `INSERT`
  89. .Synopsis:
  90. [source, sql]
  91. --------------------------------------------------
  92. INSERT(source<1>, start<2>, length<3>, replacement<4>)
  93. --------------------------------------------------
  94. *Input*:
  95. <1> string expression
  96. <2> integer expression
  97. <3> integer expression
  98. <4> string expression
  99. *Output*: string
  100. .Description:
  101. 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",subs="attributes,callouts,macros"]
  103. --------------------------------------------------
  104. include-tagged::{sql-specs}/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:
  117. Returns a string equal to that in `string_exp`, with all uppercase characters converted to lowercase.
  118. ["source","sql",subs="attributes,callouts,macros"]
  119. --------------------------------------------------
  120. include-tagged::{sql-specs}/docs.csv-spec[stringLCase]
  121. --------------------------------------------------
  122. [[sql-functions-string-left]]
  123. ==== `LEFT`
  124. .Synopsis:
  125. [source, sql]
  126. --------------------------------------------------
  127. LEFT(string_exp<1>, count<2>)
  128. --------------------------------------------------
  129. *Input*:
  130. <1> string expression
  131. <2> integer expression
  132. *Output*: string
  133. .Description:
  134. Returns the leftmost count characters of `string_exp`.
  135. ["source","sql",subs="attributes,callouts,macros"]
  136. --------------------------------------------------
  137. include-tagged::{sql-specs}/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:
  150. Returns the number of characters in `string_exp`, excluding trailing blanks.
  151. ["source","sql",subs="attributes,callouts,macros"]
  152. --------------------------------------------------
  153. include-tagged::{sql-specs}/docs.csv-spec[stringLength]
  154. --------------------------------------------------
  155. [[sql-functions-string-locate]]
  156. ==== `LOCATE`
  157. .Synopsis:
  158. [source, sql]
  159. --------------------------------------------------
  160. LOCATE(pattern<1>, source<2>[, start]<3>)
  161. --------------------------------------------------
  162. *Input*:
  163. <1> string expression
  164. <2> string expression
  165. <3> integer expression; optional
  166. *Output*: integer
  167. .Description:
  168. 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.
  169. ["source","sql",subs="attributes,callouts,macros"]
  170. --------------------------------------------------
  171. include-tagged::{sql-specs}/docs.csv-spec[stringLocateWoStart]
  172. --------------------------------------------------
  173. ["source","sql",subs="attributes,callouts,macros"]
  174. --------------------------------------------------
  175. include-tagged::{sql-specs}/docs.csv-spec[stringLocateWithStart]
  176. --------------------------------------------------
  177. [[sql-functions-string-ltrim]]
  178. ==== `LTRIM`
  179. .Synopsis:
  180. [source, sql]
  181. --------------------------------------------------
  182. LTRIM(string_exp<1>)
  183. --------------------------------------------------
  184. *Input*:
  185. <1> string expression
  186. *Output*: string
  187. .Description:
  188. Returns the characters of `string_exp`, with leading blanks removed.
  189. ["source","sql",subs="attributes,callouts,macros"]
  190. --------------------------------------------------
  191. include-tagged::{sql-specs}/docs.csv-spec[stringLTrim]
  192. --------------------------------------------------
  193. [[sql-functions-string-position]]
  194. ==== `POSITION`
  195. .Synopsis:
  196. [source, sql]
  197. --------------------------------------------------
  198. POSITION(string_exp1<1>, string_exp2<2>)
  199. --------------------------------------------------
  200. *Input*:
  201. <1> string expression
  202. <2> string expression
  203. *Output*: integer
  204. .Description:
  205. Returns the position of the `string_exp1` in `string_exp2`. The result is an exact numeric.
  206. ["source","sql",subs="attributes,callouts,macros"]
  207. --------------------------------------------------
  208. include-tagged::{sql-specs}/docs.csv-spec[stringPosition]
  209. --------------------------------------------------
  210. [[sql-functions-string-repeat]]
  211. ==== `REPEAT`
  212. .Synopsis:
  213. [source, sql]
  214. --------------------------------------------------
  215. REPEAT(string_exp<1>, count<2>)
  216. --------------------------------------------------
  217. *Input*:
  218. <1> string expression
  219. <2> integer expression
  220. *Output*: string
  221. .Description:
  222. Returns a character string composed of `string_exp` repeated `count` times.
  223. ["source","sql",subs="attributes,callouts,macros"]
  224. --------------------------------------------------
  225. include-tagged::{sql-specs}/docs.csv-spec[stringRepeat]
  226. --------------------------------------------------
  227. [[sql-functions-string-replace]]
  228. ==== `REPLACE`
  229. .Synopsis:
  230. [source, sql]
  231. --------------------------------------------------
  232. REPLACE(source<1>, pattern<2>, replacement<3>)
  233. --------------------------------------------------
  234. *Input*:
  235. <1> string expression
  236. <2> string expression
  237. <3> string expression
  238. *Output*: string
  239. .Description:
  240. Search `source` for occurrences of `pattern`, and replace with `replacement`.
  241. ["source","sql",subs="attributes,callouts,macros"]
  242. --------------------------------------------------
  243. include-tagged::{sql-specs}/docs.csv-spec[stringReplace]
  244. --------------------------------------------------
  245. [[sql-functions-string-right]]
  246. ==== `RIGHT`
  247. .Synopsis:
  248. [source, sql]
  249. --------------------------------------------------
  250. RIGHT(string_exp<1>, count<2>)
  251. --------------------------------------------------
  252. *Input*:
  253. <1> string expression
  254. <2> integer expression
  255. *Output*: string
  256. .Description:
  257. Returns the rightmost count characters of `string_exp`.
  258. ["source","sql",subs="attributes,callouts,macros"]
  259. --------------------------------------------------
  260. include-tagged::{sql-specs}/docs.csv-spec[stringRight]
  261. --------------------------------------------------
  262. [[sql-functions-string-rtrim]]
  263. ==== `RTRIM`
  264. .Synopsis:
  265. [source, sql]
  266. --------------------------------------------------
  267. RTRIM(string_exp<1>)
  268. --------------------------------------------------
  269. *Input*:
  270. <1> string expression
  271. *Output*: string
  272. .Description:
  273. Returns the characters of `string_exp` with trailing blanks removed.
  274. ["source","sql",subs="attributes,callouts,macros"]
  275. --------------------------------------------------
  276. include-tagged::{sql-specs}/docs.csv-spec[stringRTrim]
  277. --------------------------------------------------
  278. [[sql-functions-string-space]]
  279. ==== `SPACE`
  280. .Synopsis:
  281. [source, sql]
  282. --------------------------------------------------
  283. SPACE(count<1>)
  284. --------------------------------------------------
  285. *Input*:
  286. <1> integer expression
  287. *Output*: string
  288. .Description:
  289. Returns a character string consisting of `count` spaces.
  290. ["source","sql",subs="attributes,callouts,macros"]
  291. --------------------------------------------------
  292. include-tagged::{sql-specs}/docs.csv-spec[stringSpace]
  293. --------------------------------------------------
  294. [[sql-functions-string-substring]]
  295. ==== `SUBSTRING`
  296. .Synopsis:
  297. [source, sql]
  298. --------------------------------------------------
  299. SUBSTRING(source<1>, start<2>, length<3>)
  300. --------------------------------------------------
  301. *Input*:
  302. <1> string expression
  303. <2> integer expression
  304. <3> integer expression
  305. *Output*: string
  306. .Description:
  307. Returns a character string that is derived from `source`, beginning at the character position specified by `start` for `length` characters.
  308. ["source","sql",subs="attributes,callouts,macros"]
  309. --------------------------------------------------
  310. include-tagged::{sql-specs}/docs.csv-spec[stringSubString]
  311. --------------------------------------------------
  312. [[sql-functions-string-ucase]]
  313. ==== `UCASE`
  314. .Synopsis:
  315. [source, sql]
  316. --------------------------------------------------
  317. UCASE(string_exp<1>)
  318. --------------------------------------------------
  319. *Input*:
  320. <1> string expression
  321. *Output*: string
  322. .Description:
  323. Returns a string equal to that of the input, with all lowercase characters converted to uppercase.
  324. ["source","sql",subs="attributes,callouts,macros"]
  325. --------------------------------------------------
  326. include-tagged::{sql-specs}/docs.csv-spec[stringUCase]
  327. --------------------------------------------------