String Functions

Functions for performing string manipulation.

ASCII

Synopsis:

  1. ASCII(string_exp)

Input:

string expression

Output: integer

Description: Returns the ASCII code value of the leftmost character of string_exp as an integer.

  1. SELECT ASCII('Elastic');
  2. ASCII('Elastic')
  3. ----------------
  4. 69

BIT_LENGTH

Synopsis:

  1. BIT_LENGTH(string_exp)

Input:

string expression

Output: integer

Description: Returns the length in bits of the string_exp input expression.

  1. SELECT BIT_LENGTH('Elastic');
  2. BIT_LENGTH('Elastic')
  3. ---------------------
  4. 56

CHAR

Synopsis:

  1. CHAR(code)

Input:

integer expression

Output: string

Description: 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.

  1. SELECT CHAR(69);
  2. CHAR(69)
  3. ---------------
  4. E

CHAR_LENGTH

Synopsis:

  1. CHAR_LENGTH(string_exp)

Input:

string expression

Output: integer

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).

  1. SELECT CHAR_LENGTH('Elastic');
  2. CHAR_LENGTH('Elastic')
  3. ----------------------
  4. 7

CONCAT

Synopsis:

  1. CONCAT(
  2. string_exp1,
  3. string_exp2)

Input:

string expression

string expression

Output: string

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.

  1. SELECT CONCAT('Elasticsearch', ' SQL');
  2. CONCAT('Elasticsearch', ' SQL')
  3. -------------------------------
  4. Elasticsearch SQL

INSERT

Synopsis:

  1. INSERT(
  2. source,
  3. start,
  4. length,
  5. replacement)

Input:

string expression

integer expression

integer expression

string expression

Output: string

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.

  1. SELECT INSERT('Elastic ', 8, 1, 'search');
  2. INSERT('Elastic ', 8, 1, 'search')
  3. ----------------------------------
  4. Elasticsearch

LCASE

Synopsis:

  1. LCASE(string_exp)

Input:

string expression

Output: string

Description: Returns a string equal to that in string_exp, with all uppercase characters converted to lowercase.

  1. SELECT LCASE('Elastic');
  2. LCASE('Elastic')
  3. ----------------
  4. elastic

LEFT

Synopsis:

  1. LEFT(
  2. string_exp,
  3. count)

Input:

string expression

integer expression

Output: string

Description: Returns the leftmost count characters of string_exp.

  1. SELECT LEFT('Elastic',3);
  2. LEFT('Elastic',3)
  3. -----------------
  4. Ela

LENGTH

Synopsis:

  1. LENGTH(string_exp)

Input:

string expression

Output: integer

Description: Returns the number of characters in string_exp, excluding trailing blanks.

  1. SELECT LENGTH('Elastic ');
  2. LENGTH('Elastic ')
  3. --------------------
  4. 7

LOCATE

Synopsis:

  1. LOCATE(
  2. pattern,
  3. source
  4. [, start]
  5. )

Input:

string expression

string expression

integer expression; optional

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.

  1. SELECT LOCATE('a', 'Elasticsearch');
  2. LOCATE('a', 'Elasticsearch')
  3. ----------------------------
  4. 3
  1. SELECT LOCATE('a', 'Elasticsearch', 5);
  2. LOCATE('a', 'Elasticsearch', 5)
  3. -------------------------------
  4. 10

LTRIM

Synopsis:

  1. LTRIM(string_exp)

Input:

string expression

Output: string

Description: Returns the characters of string_exp, with leading blanks removed.

  1. SELECT LTRIM(' Elastic');
  2. LTRIM(' Elastic')
  3. -------------------
  4. Elastic

OCTET_LENGTH

Synopsis:

  1. OCTET_LENGTH(string_exp)

Input:

string expression

Output: integer

Description: Returns the length in bytes of the string_exp input expression.

  1. SELECT OCTET_LENGTH('Elastic');
  2. OCTET_LENGTH('Elastic')
  3. -----------------------
  4. 7

POSITION

Synopsis:

  1. POSITION(
  2. string_exp1,
  3. string_exp2)

Input:

string expression

string expression

Output: integer

Description: Returns the position of the string_exp1 in string_exp2. The result is an exact numeric.

  1. SELECT POSITION('Elastic', 'Elasticsearch');
  2. POSITION('Elastic', 'Elasticsearch')
  3. ------------------------------------
  4. 1

REPEAT

Synopsis:

  1. REPEAT(
  2. string_exp,
  3. count)

Input:

string expression

integer expression

Output: string

Description: Returns a character string composed of string_exp repeated count times.

  1. SELECT REPEAT('La', 3);
  2. REPEAT('La', 3)
  3. ----------------
  4. LaLaLa

REPLACE

Synopsis:

  1. REPLACE(
  2. source,
  3. pattern,
  4. replacement)

Input:

string expression

string expression

string expression

Output: string

Description: Search source for occurrences of pattern, and replace with replacement.

  1. SELECT REPLACE('Elastic','El','Fant');
  2. REPLACE('Elastic','El','Fant')
  3. ------------------------------
  4. Fantastic

RIGHT

Synopsis:

  1. RIGHT(
  2. string_exp,
  3. count)

Input:

string expression

integer expression

Output: string

Description: Returns the rightmost count characters of string_exp.

  1. SELECT RIGHT('Elastic',3);
  2. RIGHT('Elastic',3)
  3. ------------------
  4. tic

RTRIM

Synopsis:

  1. RTRIM(string_exp)

Input:

string expression

Output: string

Description: Returns the characters of string_exp with trailing blanks removed.

  1. SELECT RTRIM('Elastic ');
  2. RTRIM('Elastic ')
  3. -------------------
  4. Elastic

SPACE

Synopsis:

  1. SPACE(count)

Input:

integer expression

Output: string

Description: Returns a character string consisting of count spaces.

  1. SELECT SPACE(3);
  2. SPACE(3)
  3. ---------------

STARTS_WITH

Synopsis:

  1. STARTS_WITH(
  2. source,
  3. pattern)

Input:

string expression

string expression

Output: boolean value

Description: Returns true if the source expression starts with the specified pattern, false otherwise. The matching is case sensitive. If either parameters is null, the function returns null.

  1. SELECT STARTS_WITH('Elasticsearch', 'Elastic');
  2. STARTS_WITH('Elasticsearch', 'Elastic')
  3. --------------------------------
  4. true
  1. SELECT STARTS_WITH('Elasticsearch', 'ELASTIC');
  2. STARTS_WITH('Elasticsearch', 'ELASTIC')
  3. --------------------------------
  4. false

SUBSTRING

Synopsis:

  1. SUBSTRING(
  2. source,
  3. start,
  4. length)

Input:

string expression

integer expression

integer expression

Output: string

Description: Returns a character string that is derived from source, beginning at the character position specified by start for length characters.

  1. SELECT SUBSTRING('Elasticsearch', 0, 7);
  2. SUBSTRING('Elasticsearch', 0, 7)
  3. --------------------------------
  4. Elastic

TRIM

Synopsis:

  1. TRIM(string_exp)

Input:

string expression

Output: string

Description: Returns the characters of string_exp, with leading and trailing blanks removed.

  1. SELECT TRIM(' Elastic ') AS trimmed;
  2. trimmed
  3. --------------
  4. Elastic

UCASE

Synopsis:

  1. UCASE(string_exp)

Input:

string expression

Output: string

Description: Returns a string equal to that of the input, with all lowercase characters converted to uppercase.

  1. SELECT UCASE('Elastic');
  2. UCASE('Elastic')
  3. ----------------
  4. ELASTIC