2018-09-06 06:19:49 +08:00
[role="xpack"]
[[sql-functions-string]]
=== String Functions
Functions for performing string manipulation.
[[sql-functions-string-ascii]]
==== `ASCII`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
ASCII(string_exp) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
2018-09-25 07:42:18 +08:00
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: integer
2020-02-15 00:58:45 +08:00
*Description*: Returns the ASCII code value of the leftmost character of `string_exp` as an integer.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringAscii]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-bit-length]]
==== `BIT_LENGTH`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
BIT_LENGTH(string_exp) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2018-09-06 06:19:49 +08:00
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: integer
2020-02-15 00:58:45 +08:00
*Description*: Returns the length in bits of the `string_exp` input expression.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringBitLength]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-char]]
==== `CHAR`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
CHAR(code) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-18 03:50:02 +08:00
<1> integer expression between `0` and `255`. If `null`, negative, or greater
than `255`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: string
2021-06-18 03:50:02 +08:00
*Description*: Returns the character that has the ASCII code value specified by the numeric input.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringChar]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-char-length]]
==== `CHAR_LENGTH`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
CHAR_LENGTH(string_exp) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: integer
2020-02-15 00:58:45 +08:00
*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).
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringCharLength]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-concat]]
==== `CONCAT`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
CONCAT(
string_exp1, <1>
string_exp2) <2>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-18 03:50:02 +08:00
<1> string expression. Treats `null` as an empty string.
<2> string expression. Treats `null` as an empty string.
2018-09-25 07:42:18 +08:00
*Output*: string
2018-09-06 06:19:49 +08:00
2021-06-18 03:50:02 +08:00
*Description*: Returns a character string that is the result of concatenating `string_exp1` to `string_exp2`.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringConcat]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-insert]]
==== `INSERT`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
INSERT(
source, <1>
start, <2>
length, <3>
replacement) <4>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
<2> integer expression. If `null`, the function returns `null`.
<3> integer expression. If `null`, the function returns `null`.
<4> string expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: string
2020-02-15 00:58:45 +08:00
*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`.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringInsert]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-lcase]]
==== `LCASE`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
LCASE(string_exp) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: string
2020-02-15 00:58:45 +08:00
*Description*: Returns a string equal to that in `string_exp`, with all uppercase characters converted to lowercase.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLCase]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-left]]
==== `LEFT`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
LEFT(
string_exp, <1>
count) <2>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2018-09-06 06:19:49 +08:00
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
<2> integer expression. If `null`, the function returns `null`. If `0` or
negative, the function returns an empty string.
2018-09-25 07:42:18 +08:00
*Output*: string
2020-02-15 00:58:45 +08:00
*Description*: Returns the leftmost count characters of `string_exp`.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLeft]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-length]]
==== `LENGTH`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
LENGTH(string_exp) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2018-09-06 06:19:49 +08:00
2018-09-25 07:42:18 +08:00
*Output*: integer
2020-02-15 00:58:45 +08:00
*Description*: Returns the number of characters in `string_exp`, excluding trailing blanks.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLength]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-locate]]
==== `LOCATE`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
LOCATE(
pattern, <1>
source <2>
[, start]<3>
)
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-18 03:50:02 +08:00
<1> string expression. If `null`, the function returns `null`.
<2> string expression. If `null`, the function returns `null`.
<3> integer expression; optional. If `null`, `0`, `1`, negative, or not
specified, the search starts at the first character position.
2018-09-06 06:19:49 +08:00
2018-09-25 07:42:18 +08:00
*Output*: integer
2021-06-18 03:50:02 +08:00
*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. If the `pattern` is not found within `source`, the
function returns `0`.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLocateWoStart]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLocateWithStart]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-ltrim]]
==== `LTRIM`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
LTRIM(string_exp) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: string
2018-09-06 06:19:49 +08:00
2020-02-15 00:58:45 +08:00
*Description*: Returns the characters of `string_exp`, with leading blanks removed.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLTrim]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
2018-10-09 05:20:18 +08:00
[[sql-functions-string-octet-length]]
==== `OCTET_LENGTH`
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
OCTET_LENGTH(string_exp) <1>
2018-10-09 05:20:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2018-10-09 05:20:18 +08:00
*Output*: integer
2020-02-15 00:58:45 +08:00
*Description*: Returns the length in bytes of the `string_exp` input expression.
2018-10-09 05:20:18 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-10-09 05:20:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringOctetLength]
2018-10-09 05:20:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-position]]
==== `POSITION`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
POSITION(
string_exp1, <1>
string_exp2) <2>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
<2> string expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: integer
2020-02-15 00:58:45 +08:00
*Description*: Returns the position of the `string_exp1` in `string_exp2`. The result is an exact numeric.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringPosition]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-repeat]]
==== `REPEAT`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
REPEAT(
string_exp, <1>
count) <2>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2018-09-06 06:19:49 +08:00
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
<2> integer expression. If `0`, negative, or `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: string
2020-02-15 00:58:45 +08:00
*Description*: Returns a character string composed of `string_exp` repeated `count` times.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringRepeat]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-replace]]
==== `REPLACE`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
REPLACE(
source, <1>
pattern, <2>
replacement) <3>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
<2> string expression. If `null`, the function returns `null`.
<3> string expression. If `null`, the function returns `null`.
2018-09-06 06:19:49 +08:00
2018-09-25 07:42:18 +08:00
*Output*: string
2020-02-15 00:58:45 +08:00
*Description*: Search `source` for occurrences of `pattern`, and replace with `replacement`.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringReplace]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-right]]
==== `RIGHT`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
RIGHT(
string_exp, <1>
count) <2>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
<2> integer expression. If `null`, the function returns `null`. If `0` or
negative, the function returns an empty string.
2018-09-06 06:19:49 +08:00
2018-09-25 07:42:18 +08:00
*Output*: string
2020-02-15 00:58:45 +08:00
*Description*: Returns the rightmost count characters of `string_exp`.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringRight]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-rtrim]]
==== `RTRIM`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
RTRIM(string_exp) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: string
2018-09-06 06:19:49 +08:00
2020-02-15 00:58:45 +08:00
*Description*: Returns the characters of `string_exp` with trailing blanks removed.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringRTrim]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-space]]
==== `SPACE`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
SPACE(count) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> integer expression. If `null` or negative, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: string
2018-09-06 06:19:49 +08:00
2020-02-15 00:58:45 +08:00
*Description*: Returns a character string consisting of `count` spaces.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringSpace]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2018-09-06 06:19:49 +08:00
2020-05-12 20:05:43 +08:00
[[sql-functions-string-startswith]]
==== `STARTS_WITH`
.Synopsis:
[source, sql]
--------------------------------------------------
STARTS_WITH(
source, <1>
pattern) <2>
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
<2> string expression. If `null`, the function returns `null`.
2020-05-12 20:05:43 +08:00
*Output*: boolean value
2021-06-18 03:50:02 +08:00
*Description*: Returns `true` if the source expression starts with the specified
pattern, `false` otherwise. The matching is case sensitive.
2020-05-12 20:05:43 +08:00
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/docs/docs.csv-spec[stringStartsWithTrue]
--------------------------------------------------
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/docs/docs.csv-spec[stringStartsWithFalse]
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-substring]]
==== `SUBSTRING`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
SUBSTRING(
source, <1>
start, <2>
length) <3>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
<2> integer expression. If `null`, the function returns `null`.
<3> integer expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: string
2020-02-15 00:58:45 +08:00
*Description*: Returns a character string that is derived from `source`, beginning at the character position specified by `start` for `length` characters.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringSubString]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2020-06-03 20:24:30 +08:00
[[sql-functions-string-trim]]
==== `TRIM`
.Synopsis:
[source, sql]
--------------------------------------------------
TRIM(string_exp) <1>
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2020-06-03 20:24:30 +08:00
*Output*: string
*Description*: Returns the characters of `string_exp`, with leading and trailing blanks removed.
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/docs/docs.csv-spec[stringTrim]
--------------------------------------------------
2018-09-06 06:19:49 +08:00
[[sql-functions-string-ucase]]
==== `UCASE`
2018-09-25 07:42:18 +08:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-17 03:27:51 +08:00
UCASE(string_exp) <1>
2018-09-25 07:42:18 +08:00
--------------------------------------------------
*Input*:
2021-06-17 02:21:08 +08:00
<1> string expression. If `null`, the function returns `null`.
2018-09-25 07:42:18 +08:00
*Output*: string
2020-02-15 00:58:45 +08:00
*Description*: Returns a string equal to that of the input, with all lowercase characters converted to uppercase.
2018-09-06 06:19:49 +08:00
2019-06-01 01:03:41 +08:00
[source, sql]
2018-09-25 07:42:18 +08:00
--------------------------------------------------
2019-03-25 21:22:59 +08:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringUCase]
2018-09-25 07:42:18 +08:00
--------------------------------------------------