2018-09-05 18:19:49 -04:00
[role="xpack"]
[testenv="basic"]
[[sql-functions-string]]
=== String Functions
Functions for performing string manipulation.
[[sql-functions-string-ascii]]
==== `ASCII`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
ASCII(string_exp) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Input*:
<1> string expression
*Output*: integer
.Description:
Returns the ASCII code value of the leftmost character of `string_exp` as an integer.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringAscii]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-bit-length]]
==== `BIT_LENGTH`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
BIT_LENGTH(string_exp) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
<1> string expression
*Output*: integer
.Description:
Returns the length in bits of the `string_exp` input expression.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringBitLength]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-char]]
==== `CHAR`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
CHAR(code) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> integer expression
*Output*: string
.Description:
2018-09-05 18:19:49 -04:00
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.
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringChar]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-char-length]]
==== `CHAR_LENGTH`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
CHAR_LENGTH(string_exp) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
*Output*: integer
.Description:
2018-09-05 18:19:49 -04:00
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).
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringCharLength]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-concat]]
==== `CONCAT`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
CONCAT(
string_exp1, <1>
string_exp2) <2>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
<2> string expression
*Output*: string
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Description:
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.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringConcat]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-insert]]
==== `INSERT`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
INSERT(
source, <1>
start, <2>
length, <3>
replacement) <4>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
<2> integer expression
<3> integer expression
<4> string expression
*Output*: string
.Description:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
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-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringInsert]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-lcase]]
==== `LCASE`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
LCASE(string_exp) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
*Output*: string
.Description:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
Returns a string equal to that in `string_exp`, with all uppercase characters converted to lowercase.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLCase]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-left]]
==== `LEFT`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
LEFT(
string_exp, <1>
count) <2>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
<1> string expression
<2> integer expression
*Output*: string
.Description:
Returns the leftmost count characters of `string_exp`.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLeft]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-length]]
==== `LENGTH`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
LENGTH(string_exp) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Output*: integer
.Description:
Returns the number of characters in `string_exp`, excluding trailing blanks.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLength]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-locate]]
==== `LOCATE`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
LOCATE(
pattern, <1>
source <2>
[, start]<3>
)
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
<2> string expression
<3> integer expression; optional
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Output*: integer
.Description:
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.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLocateWoStart]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLocateWithStart]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-ltrim]]
==== `LTRIM`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
LTRIM(string_exp) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
*Output*: string
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Description:
Returns the characters of `string_exp`, with leading blanks removed.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringLTrim]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
2018-10-08 17:20:18 -04:00
[[sql-functions-string-octet-length]]
==== `OCTET_LENGTH`
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
OCTET_LENGTH(string_exp) <1>
2018-10-08 17:20:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
*Output*: integer
.Description:
Returns the length in bytes of the `string_exp` input expression.
2019-05-31 13:03:41 -04:00
[source, sql]
2018-10-08 17:20:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringOctetLength]
2018-10-08 17:20:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-position]]
==== `POSITION`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
POSITION(
string_exp1, <1>
string_exp2) <2>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
<2> string expression
*Output*: integer
.Description:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
Returns the position of the `string_exp1` in `string_exp2`. The result is an exact numeric.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringPosition]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-repeat]]
==== `REPEAT`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
REPEAT(
string_exp, <1>
count) <2>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
<1> string expression
<2> integer expression
*Output*: string
.Description:
Returns a character string composed of `string_exp` repeated `count` times.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringRepeat]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-replace]]
==== `REPLACE`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
REPLACE(
source, <1>
pattern, <2>
replacement) <3>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
<2> string expression
<3> string expression
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Output*: string
.Description:
Search `source` for occurrences of `pattern`, and replace with `replacement`.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringReplace]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-right]]
==== `RIGHT`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
RIGHT(
string_exp, <1>
count) <2>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
<2> integer expression
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Output*: string
.Description:
Returns the rightmost count characters of `string_exp`.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringRight]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-rtrim]]
==== `RTRIM`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
RTRIM(string_exp) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
*Output*: string
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Description:
Returns the characters of `string_exp` with trailing blanks removed.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringRTrim]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-space]]
==== `SPACE`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
SPACE(count) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> integer expression
*Output*: string
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Description:
Returns a character string consisting of `count` spaces.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringSpace]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-substring]]
==== `SUBSTRING`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
SUBSTRING(
source, <1>
start, <2>
length) <3>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
<2> integer expression
<3> integer expression
*Output*: string
.Description:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
Returns a character string that is derived from `source`, beginning at the character position specified by `start` for `length` characters.
2018-09-05 18:19:49 -04:00
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringSubString]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-ucase]]
==== `UCASE`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
2019-04-16 15:27:51 -04:00
UCASE(string_exp) <1>
2018-09-24 19:42:18 -04:00
--------------------------------------------------
*Input*:
<1> string expression
*Output*: string
.Description:
2018-09-05 18:19:49 -04:00
Returns a string equal to that of the input, with all lowercase characters converted to uppercase.
2019-05-31 13:03:41 -04:00
[source, sql]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2019-03-25 09:22:59 -04:00
include-tagged::{sql-specs}/docs/docs.csv-spec[stringUCase]
2018-09-24 19:42:18 -04:00
--------------------------------------------------