2018-09-05 18:19:49 -04:00
[role="xpack"]
[testenv="basic"]
[[sql-functions-string]]
=== String Functions
2018-12-11 05:29:44 -05:00
beta[]
2018-09-05 18:19:49 -04:00
Functions for performing string manipulation.
[[sql-functions-string-ascii]]
==== `ASCII`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
ASCII(string_exp<1>)
--------------------------------------------------
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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
BIT_LENGTH(string_exp<1>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
CHAR(code<1>)
--------------------------------------------------
*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.
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
CHAR_LENGTH(string_exp<1>)
--------------------------------------------------
*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).
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
CONCAT(string_exp1<1>,string_exp2<2>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
INSERT(source<1>, start<2>, length<3>, replacement<4>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
LCASE(string_exp<1>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
LEFT(string_exp<1>, count<2>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
LENGTH(string_exp<1>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
LOCATE(pattern<1>, source<2>[, start]<3>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/docs.csv-spec[stringLocateWoStart]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
LTRIM(string_exp<1>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
OCTET_LENGTH(string_exp<1>)
--------------------------------------------------
*Input*:
<1> string expression
*Output*: integer
.Description:
Returns the length in bytes of the `string_exp` input expression.
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[stringOctetLength]
--------------------------------------------------
2018-09-05 18:19:49 -04:00
[[sql-functions-string-position]]
==== `POSITION`
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
POSITION(string_exp1<1>, string_exp2<2>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
REPEAT(string_exp<1>, count<2>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
REPLACE(source<1>, pattern<2>, replacement<3>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
RIGHT(string_exp<1>, count<2>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
RTRIM(string_exp<1>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
SPACE(count<1>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
SUBSTRING(source<1>, start<2>, length<3>)
--------------------------------------------------
*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
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/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]
--------------------------------------------------
UCASE(string_exp<1>)
--------------------------------------------------
*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.
["source","sql",subs="attributes,callouts,macros"]
2018-09-24 19:42:18 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
include-tagged::{sql-specs}/docs.csv-spec[stringUCase]
2018-09-24 19:42:18 -04:00
--------------------------------------------------