---
title: "String functions: CONCAT, SUBSTR, REPLACE, TRIM, LPAD and more"
description: "CoraDB string functions and concatenation: length, case, padding, trimming, searching, extracting, replacing and encoding."
url: "https://www.coradb.ai/manual/sql/function/string_fn.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/function/string_fn.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb string functions, concat, concat_ws, substr, substring, substring_index, replace, translate, trim, lpad, rpad, instr, locate, position, upper, lower, length, char_length, octet_length, to_base64"
---

# String functions: CONCAT, SUBSTR, REPLACE, TRIM, LPAD and more

> **Note:**
> In the string functions, if the value of **oracle_style_empty_string** parameter is yes, CoraDB does not separate an empty string and NULL; according to each function, CoraDB regards all of them as NULL or an empty string. For the detail description, see [oracle_style_empty_string](https://www.coradb.ai/manual/admin/config_sql.html#oracle_style_empty_string).


## Concatenation operator

A concatenation operator gets a character string or bit string data type as an operand and returns a concatenated string. The plus sign (+) and double pipe symbol (\|\|) are provided as concatenation operators for character string data. If **NULL** is specified as an operand, a **NULL** value is returned.

If **pipes_as_concat** that is a parameter related to SQL statement is set to **no** (default value: yes), a double pipe (\|\|) symbol is interpreted as an **OR** operator. If plus_as_concat is set to no (default value: yes), a plus (+) symbol is interpreted as a plus (+) operator. In such case, It is recommended to concatenate strings or bit strings, by using the **CONCAT** function.

```text
<concat_operand1> +  <concat_operand1>
<concat_operand2> || <concat_operand2>

    <concat_operand1> ::=
        bit string |
        NULL

    <concat_operand2> ::=
        bit string |
        character string
        NULL
```

- \<*concat_operand1*\>: Left string after concatenation. String or bit string can be specified.
- \<*concat_operand2*\>: Right string after concatenation. String or bit string can be specified.

```sql
SELECT 'CoraDB' || ',' + '2008';
```

| 'CoraDB' \|\| ',' + '2008' |
|---|
| CoraDB,2008 |

```sql
SELECT 'coradb' || ',' || B'0010' ||B'0000' ||B'0000' ||B'1000';
```

| 'coradb' \|\| ',' \|\| B'0010' \|\|B'0000' \|\|B'0000' \|\|B'1000' |
|---|
| coradb,2008 |

Numbers are converted to strings when concatenated:

```sql
SELECT EXTRACT(YEAR FROM DATE '2026-11-17') || EXTRACT(MONTH FROM DATE '2026-11-17');
```

| EXTRACT(YEAR FROM DATE '2026-11-17') \|\| EXTRACT(MONTH FROM DATE '2026-11-17') |
|---|
| 202611 |
```sql
SELECT 'CoraDB' || ',' + NULL;
```

| 'CoraDB' \|\| ',' + NULL |
|---|
| NULL |

## ASCII

```sql
ASCII (str)
```

The **ASCII** function returns the ASCII code of the most left character in numeric value. If an input string is **NULL**, **NULL** is returned. This **ASCII** function supports single-byte character sets only. If a numeric value is entered, it is converted into character string and then the ASCII code of the most left character is returned.

**Parameters**

- `str`: Input string

**Return type:** STRING

```sql
SELECT ASCII('5');
```

| ASCII('5') |
|---|
| 53 |

```sql
SELECT ASCII('ab');
```

| ASCII('ab') |
|---|
| 97 |

## BIN

```sql
BIN (n)
```

The **BIN** function converts a **BIGINT** type number into binary string. If an input string is **NULL**, **NULL** is returned. When you input the string which cannot be transformed into **BIGINT**, it returns an error if the value of **return_null_on_function_errors** in **coradb.conf** is no(the default), or returns NULL if it is yes.

**Parameters**

- `n`: A **BIGINT** type number

**Return type:** STRING

```sql
SELECT BIN(12);
```

| BIN(12) |
|---|
| 1100 |

## BIT_LENGTH

```sql
BIT_LENGTH (string)
```

The **BIT_LENGTH** function returns the length (bits) of a character string or bit string as an integer value. The return value of the **BIT_LENGTH** function may depend on the character set, because for the character string, the number of bytes taken up by a single character is different depending on the character set of the data input environment (in UTF-8, for example, `ô` takes 2 bytes, that is 16 bits). For details about character sets supported by CoraDB, see [Character strings](https://www.coradb.ai/manual/sql/datatype_string.html#character-strings). When you input the invalid value, it returns an error if the value of **return_null_on_function_errors** in **coradb.conf** is no(the default), or returns NULL if it is yes.

**Parameters**

- `string`: Specifies the character string or bit string whose number of bits is to be calculated. If this value is **NULL**, **NULL** is returned.

**Return type:** INT

```sql
SELECT BIT_LENGTH('');
```

| BIT_LENGTH('') |
|---|
| 0 |

```sql
SELECT BIT_LENGTH('CoraDB');
```

| BIT_LENGTH('CoraDB') |
|---|
| 48 |

```sql
-- 'ô' takes two bytes in UTF-8
SELECT BIT_LENGTH('Côte');
```

| BIT_LENGTH('Côte') |
|---|
| 40 |

```sql
SELECT BIT_LENGTH(B'010101010');
```

| BIT_LENGTH(B'010101010') |
|---|
| 9 |

The character, byte and bit lengths of the product names that contain non-ASCII letters:

```sql
SELECT name, LENGTH(name) AS chars, OCTET_LENGTH(name) AS bytes, BIT_LENGTH(name) AS bits
FROM product WHERE name REGEXP '[^ -~]' ORDER BY name;
```

| name | chars | bytes | bits |
|---|---|---|---|
| Côte de Blaye | 13 | 14 | 112 |
| Guaraná Fantástica | 18 | 20 | 160 |
| Original Frankfurter Grüne Soße | 31 | 33 | 264 |
| Pâte chinois | 12 | 13 | 104 |
| Thüringer Rostbratwurst | 23 | 24 | 192 |
| Tourtière | 9 | 10 | 80 |
## CHAR_LENGTH, CHARACTER_LENGTH, LENGTHB, LENGTH


```sql
CHAR_LENGTH (string)
```


```sql
CHARACTER_LENGTH (string)
```


```sql
LENGTHB (string)
```


```sql
LENGTH (string)
```

**CHAR_LENGTH**, **CHARACTER_LENGTH**, **LENGTHB**, and **LENGTH** are used interchangeably. The number of characters is returned as an integer. For details on character set supported by CoraDB, see [An overview of globalization](https://www.coradb.ai/manual/sql/i18n.html).

**Parameters**

- `string`: Specifies the string whose length will be calculated according to the number of characters. If the character string is **NULL**, **NULL** is returned.

**Return type:** INT

> **Note:**
> - The length of each space character that is included in a character string is one byte.
> - The length of empty quotes (") to represent a space character is 0. Note that in a **CHAR** (*n*) type, the length of a space character is *n*, and it is specified as 1 if n is omitted.


```sql
SELECT LENGTH('');
```

| LENGTH('') |
|---|
| 0 |

```sql
SELECT LENGTH('CoraDB');
```

| LENGTH('CoraDB') |
|---|
| 6 |

```sql
SELECT LENGTH('Côte');
```

| LENGTH('Côte') |
|---|
| 4 |

A **CHAR**(*n*) value is padded with spaces to *n* characters, so its length is always *n*:

```sql
SELECT LENGTH(CAST('a' AS CHAR(5))), LENGTH(CAST('é' AS CHAR(5))), OCTET_LENGTH(CAST('é' AS CHAR(5)));
```

| LENGTH(CAST('a' AS CHAR(5))) | LENGTH(CAST('é' AS CHAR(5))) | OCTET_LENGTH(CAST('é' AS CHAR(5))) |
|---|---|---|
| 5 | 5 | 6 |
## CHR

```sql
CHR (number_operand [USING charset_name])
```

The **CHR** function returns a character that corresponds to the return value of the expression specified as an argument. When you input the code value within invalid ranges, it returns an error if the value of **return_null_on_function_errors** in **coradb.conf** is no(the default), or returns NULL if it is yes.

**Parameters**

- `number_operand`: Specifies an expression that returns a numeric value.
- `charset_name`: Characterset name. It supports utf8 and iso88591.

**Return type:** STRING

```sql
SELECT CHR(68) || CHR(68-2);
```

| CHR(68) \|\| CHR(68-2) |
|---|
| DB |

To get a multibyte character, pass its code in the character set with **USING**. **HEX** and **CONV** go the other way:

```sql
SELECT CHR(14909886 USING utf8), HEX('ま'), CONV('E381BE', 16, 10);
```

| CHR(14909886 USING utf8) | HEX('ま') | CONV('E381BE', 16, 10) |
|---|---|---|
| ま | E381BE | 14909886 |

## CONCAT

```sql
CONCAT (string1, string2 [,string3 [, ... [, stringN]...]])
```

The **CONCAT** function has at least one argument specified for it and returns a string as a result of concatenating all argument values. The number of parameters that can be specified is unlimited. Automatic type casting takes place if a non-string type is specified as the argument. If any of the arguments is specified as **NULL**, **NULL** is returned.

If you want to insert separators between strings specified as arguments for concatenation, use the [CONCAT_WS](https://www.coradb.ai/manual/sql/function/string_fn.html#concat_ws) Function.

**Parameters**

- `strings`: character string

**Return type:** STRING

```sql
SELECT CONCAT('CoraDB', '2008' , 'R3.0');
```

| CONCAT('CoraDB', '2008' , 'R3.0') |
|---|
| CoraDB2008R3.0 |

```sql
--it returns null when null is specified for one of parameters
SELECT CONCAT('CoraDB', '2008' , 'R3.0', NULL);
```

| CONCAT('CoraDB', '2008' , 'R3.0', NULL) |
|---|
| NULL |

```sql
--it converts number types and then returns concatenated strings
SELECT CONCAT(2008, 3.0);
```

| CONCAT(2008, 3.0) |
|---|
| 20083.0 |

## CONCAT_WS

```sql
CONCAT_WS (string1, string2 [,string3 [, ... [, stringN]...]])
```

The **CONCAT_WS** function has at least two arguments specified for it. The function uses the first argument value as the separator and returns the result.

**Parameters**

- `strings`: character string

**Return type:** STRING

```sql
SELECT CONCAT_WS(' ', 'CoraDB', '1.0', 'Manual');
```

| CONCAT_WS(' ', 'CoraDB', '1.0', 'Manual') |
|---|
| CoraDB 1.0 Manual |

```sql
--it returns strings even if null is specified for one of parameters
SELECT CONCAT_WS(' ', 'CoraDB', '1.0', NULL, 'Manual');
```

| CONCAT_WS(' ', 'CoraDB', '1.0', NULL, 'Manual') |
|---|
| CoraDB 1.0 Manual |

```sql
--it converts number types and then returns concatenated strings with separator
SELECT CONCAT_WS(' ',2008, 3.0);
```

| CONCAT_WS(' ',2008, 3.0) |
|---|
| 2008 3.0 |

## ELT

```sql
ELT (N, string1, string2, ... )
```

If *N* is 1, the **ELT** function returns *string1* and if *N* is 2, it returns *string2*. The return value is a **VARCHAR** type. You can add conditional expressions as needed.

The maximum byte length of the character string is 33,554,432 and if this length is exceeded, **NULL** will be returned.

If *N* is 0 or a negative number, an empty string will be returned. If *N* is greater than the number of this input character string, **NULL** will be returned as it is out of range. If *N* is a type that cannot be converted to an integer, an error will be returned.

**Parameters**

- `N`: A position of a string to return among the list of strings
- `strings`: The list of strings

**Return type:** STRING

```sql
SELECT ELT(3,'string1','string2','string3');
```

| ELT(3,'string1','string2','string3') |
|---|
| string3 |

```sql
SELECT ELT('3','1/1/1','23:00:00','2001-03-04');
```

| ELT('3','1/1/1','23:00:00','2001-03-04') |
|---|
| 2001-03-04 |

```sql
SELECT ELT(-1, 'string1','string2','string3');
```

| ELT(-1, 'string1','string2','string3') |
|---|
| NULL |

```sql
SELECT ELT(4,'string1','string2','string3');
```

| ELT(4,'string1','string2','string3') |
|---|
| NULL |

```sql
SELECT ELT(3.2,'string1','string2','string3');
```

| ELT(3.2,'string1','string2','string3') |
|---|
| string3 |

A first argument that cannot be converted to a number is an error:

```sql
SELECT ELT('a','string1','string2','string3');
```

```text
ERROR: Cannot coerce 'a' to type bigint.
```

## FIELD

```sql
FIELD ( search_string, string1 [,string2 [, ... [, stringN]...]])
```

The **FIELD** function returns the location index value (position) of a string of *string1*, *string2*. The function returns 0 if it does not have a parameter value which is the same as *search_string*. It returns 0 if *search_string* is **NULL** because it cannot perform the comparison operation with the other arguments.

If all arguments specified for **FIELD** function are of string type, string comparison operation is performed: if all of them are of number type, numeric comparison operation is performed. If the type of one argument is different from that of another, a comparison operation is performed by casting each argument to the type of the first argument. If type casting fails during the comparison operation with each argument, the function considers the result of the comparison operation as **FALSE** and resumes the other operations.

**Parameters**

- `search_string`: A string pattern to search
- `strings`: The list of strings to be searched

**Return type:** INT

```sql
SELECT FIELD('abc', 'a', 'ab', 'abc', 'abcd', 'abcde');
```

| FIELD('abc', 'a', 'ab', 'abc', 'abcd', 'abcde') |
|---|
| 3 |

```sql
--it returns 0 when no same string is found in the list
SELECT FIELD('abc', 'a', 'ab', NULL);
```

| FIELD('abc', 'a', 'ab', NULL) |
|---|
| 0 |

```sql
--it returns 0 when null is specified in the first parameter
SELECT FIELD(NULL, 'a', 'ab', NULL);
```

| FIELD(NULL, 'a', 'ab', NULL) |
|---|
| 0 |

```sql
SELECT FIELD('123', 1, 12, 123.0, 1234, 12345);
```

| FIELD('123', 1, 12, 123.0, 1234, 12345) |
|---|
| 0 |

```sql
SELECT FIELD(123, 1, 12, '123.0', 1234, 12345);
```

| FIELD(123, 1, 12, '123.0', 1234, 12345) |
|---|
| 3 |

## FIND_IN_SET

```sql
FIND_IN_SET (str, strlist)
```

The **FIND_IN_SET** function looks for the string *str* in the string list *strlist* and returns a position of *str* if it exists. A string list is a string composed of substrings separated by a comma (,). If *str* is not in *strlist* or *strlist* is an empty string, 0 is returned. If either argument is **NULL**, **NULL** is returned. This function does not work properly if *str* contains a comma (,).

**Parameters**

- `str`: A string to be searched
- `strlist`: A group of strings separated by a comma

**Return type:** INT

```sql
SELECT FIND_IN_SET('b','a,b,c,d');
```

| FIND_IN_SET('b','a,b,c,d') |
|---|
| 2 |

## FROM_BASE64

```sql
FROM_BASE64(str)
```

**FROM_BASE64** function returns the the decoded result as binary string from the input string encoded as base-64 rule, which is used in **TO_BASE64** function. If the input value is **NULL**, it returns **NULL. When you input the invalid base-64 string, it returns an error if the value of**return_null_on_function_errors\*\* in **coradb.conf** is no(the default); NULL if this value is yes. See [TO_BASE64](https://www.coradb.ai/manual/sql/function/string_fn.html#to_base64) for more details on base-64 encoding rules.

**Parameters**

- `str`: Input string

**Return type:** STRING

```sql
SELECT TO_BASE64('abcd'), FROM_BASE64(TO_BASE64('abcd')); 
```

| TO_BASE64('abcd') | FROM_BASE64(TO_BASE64('abcd')) |
|---|---|
| YWJjZA== | abcd |

> **See also:**
> [TO_BASE64](https://www.coradb.ai/manual/sql/function/string_fn.html#to_base64)


## INSERT

```sql
INSERT ( str, pos, len, string )
```

The **INSERT** function inserts a partial character string as long as the length from the specific location of the input character string. The return value is a **VARCHAR** type. The maximum length of the character string is 33,554,432 and if this length is exceeded, **NULL** will be returned.

**Parameters**

- `str`: Input character string
- `pos`: *str* location. Starts from 1. If *pos* is smaller than 1 or greater than the length of *string* + 1, the *string* will not be inserted and the *str* will be returned instead.
- `len`: Length of *string* to insert *pos* of *str*. If *len* exceeds the length of the partial character string, insert as many values as *string* in the *pos* of the *str* . If *len* is a negative number, *str* will be the end of the character string.
- `string`: Partial character string to insert to *str*

**Return type:** STRING

```sql
SELECT INSERT('coradb', 2, 2, 'dbsql'), INSERT('coradb', 3, 100, 'db'), INSERT('coradb', 7, 100, 'db'), INSERT('coradb', 3, -1, 'db');
```

| INSERT('coradb', 2, 2, 'dbsql') | INSERT('coradb', 3, 100, 'db') | INSERT('coradb', 7, 100, 'db') | INSERT('coradb', 3, -1, 'db') |
|---|---|---|---|
| cdbsqladb | codb | coradbdb | codb |

When *pos* is smaller than 1, *str* is returned unchanged:

```sql
SELECT INSERT('coradb', 0, 3, 'db'), INSERT('coradb', -3, 3, 'db');
```

| INSERT('coradb', 0, 3, 'db') | INSERT('coradb', -3, 3, 'db') |
|---|---|
| coradb | coradb |

## INSTR

```sql
INSTR ( string , substring [, position] )
```

The **INSTR** function, similarly to the **POSITION**, returns the position of a *substring* within *string*; the position. For the **INSTR** function, you can specify the starting position of the search for *substring* to make it possible to search for duplicate *substring*.

**Parameters**

- `string`: Specifies the input character string.
- `substring`: Specifies the character string whose position is to be returned.
- `position`: Optional. Represents the position of a *string* where the search begins in character unit. If omitted, the default value 1 is applied. The first position of the *string* is specified as 1. If the value is negative, the system counts backward from the end of the *string*.

**Return type:** INT

> **Note:**
>


```sql
--it returns position of the first 'b'
SELECT INSTR ('12345abcdeabcde','b');
```

| INSTR ('12345abcdeabcde','b') |
|---|
| 7 |

```sql
-- it returns position of the first 'É'
SELECT INSTR ('12345ÀÉÎÕÜÀÉÎÕÜ', 'É' );
```

| INSTR ('12345ÀÉÎÕÜÀÉÎÕÜ', 'É' ) |
|---|
| 7 |

```sql
-- it returns position of the second 'É'
SELECT INSTR ('12345ÀÉÎÕÜÀÉÎÕÜ', 'É', 11 );
```

| INSTR ('12345ÀÉÎÕÜÀÉÎÕÜ', 'É', 11 ) |
|---|
| 12 |

```sql
--it returns position of the 'b' searching from the 8th position
SELECT INSTR ('12345abcdeabcde','b', 8);
```

| INSTR ('12345abcdeabcde','b', 8) |
|---|
| 12 |

```sql
--it returns position of the 'b' searching backwardly from the end
SELECT INSTR ('12345abcdeabcde','b', -1);
```

| INSTR ('12345abcdeabcde','b', -1) |
|---|
| 12 |

```sql
--it returns position of the 'b' searching backwardly from a specified position
SELECT INSTR ('12345abcdeabcde','b', -8);
```

| INSTR ('12345abcdeabcde','b', -8) |
|---|
| 7 |

## LCASE, LOWER


```sql
LCASE (string)
```


```sql
LOWER (string)
```

The functions **LCASE** and **LOWER** are used interchangeably. They convert uppercase characters included in string to lowercase characters.

**Parameters**

- `string`: Specifies the string in which uppercase characters are to be converted to lowercase. If the value is **NULL**, **NULL** is returned.

**Return type:** STRING

```sql
SELECT LOWER('');
```

| LOWER('') |
|---|
|   |

```sql
SELECT LOWER(NULL);
```

| LOWER(NULL) |
|---|
| NULL |

```sql
SELECT LOWER('CoraDB');
```

| LOWER('CoraDB') |
|---|
| coradb |

**LOWER** converts letters according to the collation of its argument. With the default collation (`utf8_bin`) and the English collations, only ASCII letters are converted. The Turkish collation `utf8_tr_cs` applies the Turkish rules for the dotted and dotless I:

```sql
SELECT LOWER('ÀÉÎ'), LOWER('İSTANBUL' COLLATE utf8_tr_cs);
```

| LOWER('ÀÉÎ') | LOWER('İSTANBUL' COLLATE utf8_tr_cs) |
|---|---|
| ÀÉÎ | istanbul |

For supporting collations in CoraDB, see [CoraDB collation](https://www.coradb.ai/manual/sql/i18n.html#coradb-collation).

## LEFT

```sql
LEFT ( string , length )
```

The **LEFT** function returns a length number of characters from the leftmost *string*. If any of the arguments is **NULL**, **NULL** is returned. If a value greater than the *length* of the *string* or a negative number is specified for a length, the entire string is returned. To extract a length number of characters from the rightmost string, use the [RIGHT](https://www.coradb.ai/manual/sql/function/string_fn.html#right).

**Parameters**

- `string`: Input string
- `length`: The length of a string to be returned

**Return type:** STRING

```sql
SELECT LEFT('CoraDB', 3);
```

| LEFT('CoraDB', 3) |
|---|
| Cor |

```sql
SELECT LEFT('CoraDB', 10);
```

| LEFT('CoraDB', 10) |
|---|
| CoraDB |

## LOCATE

```sql
LOCATE ( substring, string [, position] )
```

The **LOCATE** function returns the location index value of a *substring* within a character string. The third argument *position* can be omitted. If this argument is specified, the function searches for *substring* from the given position and returns the location index value of the first occurrence. If the *substring* cannot be found within the string, 0 is returned. The **LOCATE** function behaves like [POSITION](https://www.coradb.ai/manual/sql/function/string_fn.html#position).

**Parameters**

- `substring`: A string pattern to search
- `string`: A whole string to be searched
- `position`: Starting position of a whole string to be searched

**Return type:** INT

```sql
--it returns 1 when substring is empty space
SELECT LOCATE ('', '12345abcdeabcde');
```

| LOCATE ('', '12345abcdeabcde') |
|---|
| 1 |

```sql
--it returns position of the first 'abc'
SELECT LOCATE ('abc', '12345abcdeabcde');
```

| LOCATE ('abc', '12345abcdeabcde') |
|---|
| 6 |

```sql
--it returns position of the second 'abc'
SELECT LOCATE ('abc', '12345abcdeabcde', 8);
```

| LOCATE ('abc', '12345abcdeabcde', 8) |
|---|
| 11 |

```sql
--it returns 0 when no substring found in the string
SELECT LOCATE ('ABC', '12345abcdeabcde');
```

| LOCATE ('ABC', '12345abcdeabcde') |
|---|
| 0 |

## LPAD

```sql
LPAD ( char1, n, [, char2 ] )
```

The **LPAD** function pads the left side of a string until the string length reaches the specified value.

**Parameters**

- `char1`: Specifies the string to pad characters to. If *n* is smaller than the length of *char1*, padding is not performed, and *char1* is truncated to length n and then returned. If the value is **NULL**, **NULL** is returned.
- `n`: Specifies the total length of *char1* in bytes. If the value is **NULL**, **NULL** is returned.
- `char2`: Specifies the string to pad to the left until the length of *char1* reaches *n*. If it is not specified, empty characters (' ') are used as a default. If the value is **NULL**, **NULL** is returned.

**Return type:** STRING

> **Note:**
> When the value is **NULL**, **NULL** is returned as its result.


If *n* is smaller than the length of the string, the string is cut to *n* characters:

```sql
SELECT LPAD('CoraDB', 3, '?'), LPAD('Côte', 3, '?');
```

| LPAD('CoraDB', 3, '?') | LPAD('Côte', 3, '?') |
|---|---|
| Cor | Côt |

```sql
--padding spaces on the left till char_length is 10
SELECT CONCAT('[', LPAD('CoraDB', 10), ']');
```

| CONCAT('[', LPAD('CoraDB', 10), ']') |
|---|
| [    CoraDB] |

```sql
--padding specific characters on the left till char_length is 10
SELECT LPAD ('CoraDB', 10, '?');
```

| LPAD ('CoraDB', 10, '?') |
|---|
| ????CoraDB |

```sql
--padding specific characters on the left till char_length is 10
SELECT LPAD ('Côte', 10, '?');
```

| LPAD ('Côte', 10, '?') |
|---|
| ??????Côte |

```sql
--padding 4 characters on the left
SELECT LPAD ('Côte', LENGTH('Côte')+4, '?');
```

| LPAD ('Côte', LENGTH('Côte')+4, '?') |
|---|
| ????Côte |

## LTRIM

```sql
LTRIM ( string [, trim_string])
```

The **LTRIM** function removes all specified characters from the left-hand side of a string.

**Parameters**

- `string`: Enters a string or string-type column to trim. If this value is **NULL**, **NULL** is returned.
- `trim_string`: You can specify a specific string to be removed in the left side of *string*. If it is not specified, empty characters (' ') is automatically specified so that the empty characters in the left side are removed.

**Return type:** STRING

```sql
--trimming spaces on the left
SELECT CONCAT('[', LTRIM('     Olympic     '), ']');
```

| CONCAT('[', LTRIM('     Olympic     '), ']') |
|---|
| [Olympic     ] |

```sql
--If NULL is specified, it returns NULL
SELECT LTRIM ('iiiiiOlympiciiiii', NULL);
```

| LTRIM ('iiiiiOlympiciiiii', NULL) |
|---|
| NULL |

```sql
-- trimming specific strings on the left
SELECT LTRIM ('iiiiiOlympiciiiii', 'i');
```

| LTRIM ('iiiiiOlympiciiiii', 'i') |
|---|
| Olympiciiiii |

## MID

```sql
MID ( string, position, substring_length )
```

The **MID** function extracts a string with the length of *substring_length* from a *position* within the *string* and then returns it. If a negative number is specified as a *position* value, the *position* is calculated in a reverse direction from the end of the *string*. **substring_length** cannot be omitted. If a negative value is specified, the function considers this as 0 and returns an empty string.

The **MID** function is working like the [SUBSTR](https://www.coradb.ai/manual/sql/function/string_fn.html#substr), but there are differences in that it cannot be used for bit strings, that the *substring_length* argument must be specified, and that it returns an empty string if a negative number is specified for *substring_length*.

**Parameters**

- `string`: Specifies an input character string. If this value is **NULL**, **NULL** is returned.
- `position`: Specifies the starting position from which the string is to be extracted. The position of the first character is 1. It is considered to be 1 even if it is specified as 0. If the input value is **NULL**, **NULL** is returned.
- `substring_length`: Specifies the length of the string to be extracted. If 0 or a negative number is specified, an empty string is returned; if **NULL** is specified, **NULL** is returned.

**Return type:** STRING

**MID**, **SUBSTR** and **SUBSTRING** differ for negative arguments:

```sql
SELECT MID('12345abcdeabcde', 6, 4), SUBSTR('12345abcdeabcde', 6, 4), SUBSTRING('12345abcdeabcde', 6, 4);
```

| MID('12345abcdeabcde', 6, 4) | SUBSTR('12345abcdeabcde', 6, 4) | SUBSTRING('12345abcdeabcde', 6, 4) |
|---|---|---|
| abcd | abcd | abcd |

A negative position counts from the end of the string for **MID** and **SUBSTR**:

```sql
SELECT MID('12345abcdeabcde', -6, 4), SUBSTR('12345abcdeabcde', -6, 4);
```

| MID('12345abcdeabcde', -6, 4) | SUBSTR('12345abcdeabcde', -6, 4) |
|---|---|
| eabc | eabc |

A negative length gives an empty string with **MID** and **NULL** with **SUBSTR**:

```sql
SELECT CONCAT('[', MID('12345abcdeabcde', 6, -4), ']'), SUBSTR('12345abcdeabcde', 6, -4);
```

| CONCAT('[', MID('12345abcdeabcde', 6, -4), ']') | SUBSTR('12345abcdeabcde', 6, -4) |
|---|---|
| [] | NULL |


## OCTET_LENGTH

```sql
OCTET_LENGTH ( string )
```

The **OCTET_LENGTH** function returns the length (byte) of a character string or bit string as an integer. Therefore, it returns 1 (byte) if the length of the bit string is 8 bits, but 2 (bytes) if the length is 9 bits.

**Parameters**

- `string`: Specifies the character or bit string whose length is to be returned in bytes. If the value is **NULL**, **NULL** is returned.

**Return type:** INT

```sql
SELECT OCTET_LENGTH('');
```

| OCTET_LENGTH('') |
|---|
| 0 |

```sql
SELECT OCTET_LENGTH('CoraDB');
```

| OCTET_LENGTH('CoraDB') |
|---|
| 6 |

```sql
SELECT OCTET_LENGTH('Côte');
```

| OCTET_LENGTH('Côte') |
|---|
| 5 |

```sql
SELECT OCTET_LENGTH(B'010101010');
```

| OCTET_LENGTH(B'010101010') |
|---|
| 2 |

See also the product-name example under [BIT_LENGTH](https://www.coradb.ai/manual/sql/function/string_fn.html#bit_length).
## POSITION

```sql
POSITION ( substring IN string )
```

The **POSITION** function returns the position of a character string corresponding to *substring* within a character string corresponding to *string*.

The return value is the position in characters, an integer greater than or equal to 0.

The **POSITION** function is occasionally used in combination with other functions. For example, if you want to extract a certain string from another string, you can use the result of the **POSITION** function as an input to the **SUBSTRING** function.

**Parameters**

- `substring`: Specifies the character string whose position is to be returned. If the value is an empty character, 1 is returned. If the value is **NULL**, **NULL** is returned.

**Return type:** INT

```sql
--it returns 1 when substring is empty space
SELECT POSITION ('' IN '12345abcdeabcde');
```

| POSITION ('' IN '12345abcdeabcde') |
|---|
| 1 |

```sql
--it returns position of the first 'b'
SELECT POSITION ('b' IN '12345abcdeabcde');
```

| POSITION ('b' IN '12345abcdeabcde') |
|---|
| 7 |

```sql
-- it returns position of the first 'É'
SELECT POSITION ('É' IN '12345ÀÉÎÕÜÀÉÎÕÜ');
```

| POSITION ('É' IN '12345ÀÉÎÕÜÀÉÎÕÜ') |
|---|
| 7 |

```sql
--it returns 0 when no substring found in the string
SELECT POSITION ('f' IN '12345abcdeabcde');
```

| POSITION ('f' IN '12345abcdeabcde') |
|---|
| 0 |

## REPEAT

```sql
REPEAT( string, count )
```

The **REPEAT** function returns the character string with a length equal to the number of repeated input character strings. The return value is a **VARCHAR** type. The maximum length of the character string is 33,554,432 and if it this length is exceeded, **NULL** will be returned. If one of the parameters is **NULL**, **NULL** will be returned.

**Parameters**

- `substring`: Character string
- `count`: Repeat count. If you enter 0 or a negative number, an empty string will be returned and if you enter a non-numeric data type, an error will be returned.

**Return type:** STRING

```sql
SELECT REPEAT('coradb',3);
```

| REPEAT('coradb',3) |
|---|
| coradbcoradbcoradb |

```sql
SELECT REPEAT('coradb',32000000);
```

```text
repeat('coradb', 32000000)
======================
NULL
```

```sql
SELECT REPEAT('coradb',-1);
```

| REPEAT('coradb',-1) |
|---|
|   |

```sql
SELECT REPEAT('coradb','a');
```

```text
ERROR: Cannot coerce 'a' to type integer.
```

## REPLACE

```sql
REPLACE ( string, search_string [, replacement_string ] )
```

The **REPLACE** function searches for a character string, *search_string*, within a given character string, *string*, and replaces it with a character string, *replacement_string*. If the string to be replaced, *replacement_string* is omitted, all *search_strings* retrieved from *string* are removed. If **NULL** is specified as an argument, **NULL** is returned.

**Parameters**

- `string`: Specifies the original string. If the value is **NULL**, **NULL** is returned.
- `search_string`: Specifies the string to be searched. If the value is **NULL**, **NULL** is returned
- `replacement_string`: Specifies the string to replace the *search_string*. If this value is omitted, *string* is returned with the *search_string* removed. If the value is **NULL**, **NULL** is returned.

**Return type:** STRING

```sql
SELECT REPLACE('12345abcdeabcde', 'abcde', 'ABCDE'), REPLACE('12345abcdeabcde', 'abcde');
```

| REPLACE('12345abcdeabcde', 'abcde', 'ABCDE') | REPLACE('12345abcdeabcde', 'abcde') |
|---|---|
| 12345ABCDEABCDE | 12345 |

Every occurrence is replaced; without *replace_string*, the occurrences are removed. If an argument is **NULL**, the result is **NULL**.

Removing the dashes from customer phone numbers:

```sql
SELECT id, phone, REPLACE(phone, '-', '') AS no_dashes FROM customer WHERE id < 4 ORDER BY id;
```

| id | phone | no_dashes |
|---|---|---|
| 0 | 001-800-310-4977 | 0018003104977 |
| 1 | 122-213-1333 | 1222131333 |
| 2 | 7443494058 | 7443494058 |
| 3 | +1-435-097-0394 | +14350970394 |

## REVERSE

```sql
REVERSE( string )
```

The **REVERSE** function returns *string* converted in the reverse order.

**Parameters**

- `string`: Specifies an input character string. If the value is an empty string, empty value is returned. If the value is NULL, NULL is returned.

**Return type:** STRING

```sql
SELECT REVERSE('CoraDB');
```

| REVERSE('CoraDB') |
|---|
| BDaroC |

## RIGHT

```sql
RIGHT ( string , length )
```

The **RIGHT** function returns a *length* number of characters from the rightmost *string*. If any of the arguments is **NULL**, **NULL** is returned. If a value greater than the length of the *string* or a negative number is specified for a *length*, the entire string is returned. To extract a length number of characters from the leftmost string, use the [LEFT](https://www.coradb.ai/manual/sql/function/string_fn.html#left).

**Parameters**

- `string`: Input string
- `length`: The length of a string to be returned

**Return type:** STRING

```sql
SELECT RIGHT('CoraDB', 3);
```

| RIGHT('CoraDB', 3) |
|---|
| aDB |

```sql
SELECT RIGHT ('CoraDB', 10);
```

| RIGHT ('CoraDB', 10) |
|---|
| CoraDB |

## RPAD

```sql
RPAD( char1, n, [, char2 ] )
```

The **RPAD** function pads the right side of a string until the string length reaches the specified value.

**Parameters**

- `char1`: Specifies the string to pad characters to. If *n* is smaller than the length of *char1*, padding is not performed, and *char1* is truncated to length *n* and then returned. If the value is **NULL**, **NULL** is specified.
- `n`: Specifies the total length of *char1*. If the value is **NULL**, **NULL** is specified.
- `char2`: Specifies the string to pad to the right until the length of *char1* reaches *n*. If it is not specified, empty characters (' ') are used as a default. If the value is **NULL**, **NULL** is returned.

**Return type:** STRING

> **Note:**
> When the value is **NULL**, **NULL** is returned as its result.


```sql
--it returns only 3 characters if not enough length is specified
SELECT RPAD ('CoraDB', 3, '?');
```

| RPAD ('CoraDB', 3, '?') |
|---|
| Cor |

```sql
--on multi-byte charset, it returns the first character only with a right-padded space
SELECT RPAD ('Côte', 3, '?');
```

| RPAD ('Côte', 3, '?') |
|---|
| Côt |

```sql
--padding spaces on the right till char_length is 10
SELECT CONCAT('[', RPAD('CoraDB', 10), ']');
```

| CONCAT('[', RPAD('CoraDB', 10), ']') |
|---|
| [CoraDB    ] |

```sql
--padding specific characters on the right till char_length is 10
SELECT RPAD ('CoraDB', 10, '?');
```

| RPAD ('CoraDB', 10, '?') |
|---|
| CoraDB???? |

```sql
--padding specific characters on the right till char_length is 10
SELECT RPAD ('Côte', 10, '?');
```

| RPAD ('Côte', 10, '?') |
|---|
| Côte?????? |

```sql
--padding 4 characters on the right
SELECT RPAD ('Côte', LENGTH('Côte')+4, '?');
```

| RPAD ('Côte', LENGTH('Côte')+4, '?') |
|---|
| Côte???? |

## RTRIM

```sql
RTRIM ( string [, trim_string])
```

The **RTRIM** function removes specified characters from the right-hand side of a string.

**Parameters**

- `string`: Enters a string or string-type column to trim. If this value is **NULL**, **NULL** is returned.
- `trim_string`: You can specify a specific string to be removed in the right side of *string*. If it is not specified, empty characters (' ') is automatically specified so that the empty characters in the right side are removed.

**Return type:** STRING

```sql
SELECT CONCAT('[', RTRIM('     Olympic     '), ']');
```

| CONCAT('[', RTRIM('     Olympic     '), ']') |
|---|
| [     Olympic] |

```sql
--If NULL is specified, it returns NULL
SELECT RTRIM ('iiiiiOlympiciiiii', NULL);
```

| RTRIM ('iiiiiOlympiciiiii', NULL) |
|---|
| NULL |

```sql
-- trimming specific strings on the right
SELECT RTRIM ('iiiiiOlympiciiiii', 'i');
```

| RTRIM ('iiiiiOlympiciiiii', 'i') |
|---|
| iiiiiOlympic |

## SPACE

```sql
SPACE (N)
```

The **SPACE** function returns as many empty strings as the number specified. The return value is a **VARCHAR** type.

**Parameters**

- `N`: Space count. It cannot be greater than the value specified in the system parameter, **string_max_size_bytes** (default 1048576). If it exceeds the specified value, **NULL** will be returned. The maximum value is 33,554,432; if this length is exceeded, **NULL** will be returned. If you enter 0 or a negative number, an empty string will be returned; if you enter a type that can't be converted to a numeric value, an error will be returned.

**Return type:** STRING

```sql
SELECT CONCAT('[', SPACE(8), ']');
```

| CONCAT('[', SPACE(8), ']') |
|---|
| [        ] |

```sql
SELECT LENGTH(space(1048576));
```

| LENGTH(space(1048576)) |
|---|
| 1048576 |

```sql
SELECT LENGTH(space(1048577));
```

| LENGTH(space(1048577)) |
|---|
| NULL |

```sql
SELECT SPACE('aaa');
```

```text
ERROR: Cannot coerce 'aaa' to type bigint.
```

## STRCMP

```sql
STRCMP( string1 , string2 )
```

The **STRCMP** function compares two strings, *string1* and *string2*, and returns 0 if they are identical, 1 if *string1* is greater, or -1 if *string1* is smaller. If any of the parameters is **NULL**, **NULL** is returned.

**Parameters**

- `string1`: A string to be compared
- `string2`: A string to be compared

**Return type:** INT

```sql
SELECT STRCMP('abc', 'abc');
```

| STRCMP('abc', 'abc') |
|---|
| 0 |

```sql
SELECT STRCMP ('acc', 'abc');
```

| STRCMP ('acc', 'abc') |
|---|
| 1 |

STRCMP follows the collation of its arguments. With the default, case-sensitive collation, uppercase letters sort before lowercase ones; with a case-insensitive collation such as `utf8_en_ci`, case is ignored:

```sql
SELECT STRCMP('ABC', 'abc'), STRCMP('ABC' COLLATE utf8_en_ci, 'abc' COLLATE utf8_en_ci);
```

| STRCMP('ABC', 'abc') | STRCMP('ABC' COLLATE utf8_en_ci, 'abc' COLLATE utf8_en_ci) |
|---|---|
| -1 | 0 |

## SUBSTR

```sql
SUBSTR ( string, position [, substring_length])
```

The **SUBSTR** function extracts a character string with the length of *substring_length* from a position, *position*, within character string, *string*, and then returns it.

> **Note:**
>


**Parameters**

- `string`: Specifies the input character string. If the input value is **NULL**, **NULL** is returned.
- `position`: Specifies the position from where the string is to be extracted in bytes. Even though the position of the first character is specified as 1 or a negative number, it is considered as 1. If a value greater than the string length or **NULL** is specified, **NULL** is returned.
- `substring_length`: Specifies the length of the string to be extracted in bytes. If this argument is omitted, character strings between the given position, *position*, and the end of them are extracted. **NULL** cannot be specified as an argument value of this function. If 0 is specified, an empty string is returned; if a negative value is specified, **NULL** is returned.

**Return type:** STRING

```sql
--it returns empty string when substring_length is 0
SELECT SUBSTR('12345abcdeabcde',6, 0);
```

| SUBSTR('12345abcdeabcde',6, 0) |
|---|
|   |

```sql
--it returns 4-length substrings counting from the position
SELECT SUBSTR('12345abcdeabcde', 6, 4), SUBSTR('12345abcdeabcde', -6, 4);
```

| SUBSTR('12345abcdeabcde', 6, 4) | SUBSTR('12345abcdeabcde', -6, 4) |
|---|---|
| abcd | eabc |

```sql
--it returns substrings counting from the position to the end
SELECT SUBSTR('12345abcdeabcde', 6), SUBSTR('12345abcdeabcde', -6);
```

| SUBSTR('12345abcdeabcde', 6) | SUBSTR('12345abcdeabcde', -6) |
|---|---|
| abcdeabcde | eabcde |

```sql
-- it returns 4-length substrings counting from 11th position
SELECT SUBSTR ('12345ÀÉÎÕÜÀÉÎÕÜ', 11 , 4);
```

| SUBSTR ('12345ÀÉÎÕÜÀÉÎÕÜ', 11 , 4) |
|---|
| ÀÉÎÕ |

## SUBSTRING

```sql
SUBSTRING ( string, position [, substring_length]),
```

```sql
SUBSTRING ( string FROM position [FOR substring_length] )
```

The **SUBSTRING** function, operating like **SUBSTR**, extracts a character string having the length of *substring_length* from a position, *position*, within character string, *string*, and returns it. If a negative number is specified as the *position* value, the **SUBSTRING** function treats it as 1 (so `SUBSTRING('12345abcdeabcde', -6, 4)` returns `1234`), while the **SUBSTR** function calculates the position from the end of the string. If a negative number is specified as the *substring_length* value, the **SUBSTRING** function handles it as if the argument were omitted, but the **SUBSTR** function returns **NULL**.

**Parameters**

- `string`: Specifies the input character string. If the input value is **NULL**, **NULL** is returned.
- `position`: Specifies the position from where the string is to be extracted. If the position of the first character is specified as 0 or a negative number, it is considered as 1. If a value greater than the string length is specified, an empty string is returned. If **NULL**, **NULL** is returned.
- `substring_length`: Specifies the length of the string to be extracted. If this argument is omitted, character strings between the given position, *position*, and the end of them are extracted. If 0 is specified, an empty string is returned; a negative value is ignored, as if the argument were omitted.

**Return type:** STRING

```sql
SELECT SUBSTRING('12345abcdeabcde', -6 ,4), SUBSTR('12345abcdeabcde', -6 ,4);
```

| SUBSTRING('12345abcdeabcde', -6 ,4) | SUBSTR('12345abcdeabcde', -6 ,4) |
|---|---|
| 1234 | eabc |

```sql
SELECT SUBSTRING('12345abcdeabcde', 16), SUBSTR('12345abcdeabcde', 16);
```

| SUBSTRING('12345abcdeabcde', 16) | SUBSTR('12345abcdeabcde', 16) |
|---|---|
|   | NULL |

```sql
SELECT SUBSTRING('12345abcdeabcde', 6, -4), SUBSTR('12345abcdeabcde', 6, -4);
```

| SUBSTRING('12345abcdeabcde', 6, -4) | SUBSTR('12345abcdeabcde', 6, -4) |
|---|---|
| abcdeabcde | NULL |

## SUBSTRING_INDEX

```sql
SUBSTRING_INDEX (string, delim, count)
```

The **SUBSTRING_INDEX** function counts the separators included in the partial character string and will return the partial character string before the *count*-th separator. The return value is a **VARCHAR** type.

**Parameters**

- `string`: Input character string. The maximum length is 33,554,432 and if this length is exceeded, **NULL** will be returned.
- `delim`: Delimiter. It is case-sensitive.
- `count`: Delimiter occurrence count. If you enter a positive number, it counts the character string from the left and if you enter a negative number, it counts it from the right. If it is 0, an empty string will be returned. If the type cannot be converted, an error will be returned.

**Return type:** STRING

```sql
SELECT SUBSTRING_INDEX('www.coradb.ai','.','2');
```

| `SUBSTRING_INDEX('www.coradb.ai','.','2')` |
|---|
| `www.coradb` |

```sql
SELECT SUBSTRING_INDEX('www.coradb.ai','.','2.3');
```

| `SUBSTRING_INDEX('www.coradb.ai','.','2.3')` |
|---|
| `www.coradb` |

```sql
SELECT SUBSTRING_INDEX('www.coradb.ai',':','2.3');
```

| `SUBSTRING_INDEX('www.coradb.ai',':','2.3')` |
|---|
| `www.coradb.ai` |

```sql
SELECT SUBSTRING_INDEX('www.coradb.ai','coradb',1);
```

| `SUBSTRING_INDEX('www.coradb.ai','coradb',1)` |
|---|
| `www.` |

```sql
SELECT SUBSTRING_INDEX('www.coradb.ai','.',100);
```

| `SUBSTRING_INDEX('www.coradb.ai','.',100)` |
|---|
| `www.coradb.ai` |

## TO_BASE64

```sql
TO_BASE64(str)
```

Returns the result as the transformed base-64 string. If the input argument is not a string, it is changed into a string before it is transformed. If the input argument is **NULL**, it returns **NULL**. The base-64 encoded string can be decoded with [FROM_BASE64](https://www.coradb.ai/manual/sql/function/string_fn.html#from_base64) function.

**Parameters**

- `str`: Input string

**Return type:** STRING

```sql
SELECT TO_BASE64('abcd'), FROM_BASE64(TO_BASE64('abcd')); 
```

| TO_BASE64('abcd') | FROM_BASE64(TO_BASE64('abcd')) |
|---|---|
| YWJjZA== | abcd |

The following is rules for [TO_BASE64](https://www.coradb.ai/manual/sql/function/string_fn.html#to_base64) function and [FROM_BASE64](https://www.coradb.ai/manual/sql/function/string_fn.html#from_base64).

- The encoded character for the alphabet value 62 is '+'.
- The encoded character for the alphabet value 63 is '/'.
- The encoded result consists of character groups, and each group has 4 characters which can be printed out. The 3 bytes of the input data are encoded into 4 bytes. If the last group are not filled with 4 characters, '=' character is padded into that group and 4 characters are made.
- To divide the long output into the several lines, a newline is added into each 76 encoded output characters.
- Decoding process indicates newline, carriage return, tab, and space and ignore them.

> **See also:**
> [FROM_BASE64](https://www.coradb.ai/manual/sql/function/string_fn.html#from_base64)


## TRANSLATE

```sql
TRANSLATE ( string, from_substring, to_substring )
```

The **TRANSLATE** function replaces a character into the character specified in *to_substring* if the character exists in the specified *string*. Correspondence relationship is determined based on the order of characters specified in *from_substring* and *to_substring*. Any characters in *from_substring* that do not have one on one relationship to *to_substring* are all removed. This function is working like the [REPLACE](https://www.coradb.ai/manual/sql/function/string_fn.html#replace) but the argument of *to_substring* cannot be omitted in this function.

**Parameters**

- `string`: Specifies the original string. If the value is **NULL**, **NULL** is returned.
- `from_substring`: Specifies the string to be retrieved. If the value is **NULL**, **NULL** is returned.
- `to_substring`: Specifies the character string in the *from_substring* to be replaced. It cannot be omitted. If the value is **NULL**, **NULL** is returned.

**Return type:** STRING

```sql
--it returns NULL when an argument is specified with NULL value
SELECT TRANSLATE('12345abcdeabcde','abcde', NULL);
```

| TRANSLATE('12345abcdeabcde','abcde', NULL) |
|---|
| NULL |

```sql
--it translates 'a','b','c','d','e' into '1', '2', '3', '4', '5' respectively
SELECT TRANSLATE('12345abcdeabcde', 'abcde', '12345');
```

| TRANSLATE('12345abcdeabcde', 'abcde', '12345') |
|---|
| 123451234512345 |

```sql
--it translates 'a','b','c' into '1', '2', '3' respectively and removes 'd's and 'e's
SELECT TRANSLATE('12345abcdeabcde','abcde', '123');
```

| TRANSLATE('12345abcdeabcde','abcde', '123') |
|---|
| 12345123123 |

```sql
--it removes 'a's,'b's,'c's,'d's, and 'e's in the string
SELECT TRANSLATE('12345abcdeabcde','abcde', '');
```

| TRANSLATE('12345abcdeabcde','abcde', '') |
|---|
| 12345 |

```sql
--it only translates 'a','b','c' into '3', '4', '5' respectively
SELECT TRANSLATE('12345abcdeabcde','ABabc', '12345');
```

| TRANSLATE('12345abcdeabcde','ABabc', '12345') |
|---|
| 12345345de345de |

## TRIM

```sql
TRIM ( [ [ LEADING | TRAILING | BOTH ] [ trim_string ] FROM ] string )
```

The **TRIM** function removes specific characters which are located before and after the string.

**Parameters**

- `trim_string`: Specifies a specific string to be removed that is in front of or at the back of the target string. If it is not specified, an empty character (' ') is automatically specified so that spaces in front of or at the back of the target string are removed.
- `string`: Enters a string or string-type column to trim. If this value is **NULL**, **NULL** is returned.

**Return type:** STRING

- **\[LEADING\|TRAILING\|BOTH\]** : You can specify an option to trim a specified string that is in a certain position of the target string. If it is **LEADING**, trimming is performed in front of a character string if it is **TRAILING**, trimming is performed at the back of a character string if it is **BOTH**, trimming is performed in front and at the back of a character string. If the option is not specified, **BOTH** is specified by default.
- The character string of *trim_string* and *string* should have the same character set.

```sql
--trimming NULL returns NULL
SELECT TRIM (NULL);
```

| TRIM (NULL) |
|---|
| NULL |

```sql
--trimming spaces on both leading and trailing parts
SELECT CONCAT('[', TRIM('     Olympic     '), ']');
```

| CONCAT('[', TRIM('     Olympic     '), ']') |
|---|
| [Olympic] |

```sql
SELECT TRIM('i' FROM 'iiiiiOlympiciiiii'), TRIM(LEADING 'i' FROM 'iiiiiOlympiciiiii'), TRIM(TRAILING 'i' FROM 'iiiiiOlympiciiiii');
```

| TRIM('i' FROM 'iiiiiOlympiciiiii') | TRIM(LEADING 'i' FROM 'iiiiiOlympiciiiii') | TRIM(TRAILING 'i' FROM 'iiiiiOlympiciiiii') |
|---|---|---|
| Olympic | Olympiciiiii | iiiiiOlympic |

## UCASE, UPPER


```sql
UCASE ( string )
```


```sql
UPPER ( string )
```

The function **UCASE** or **UPPER** converts lowercase characters that are included in a character string to uppercase characters.

**Parameters**

- `string`: Specifies the string in which lowercase characters are to be converted to uppercase. If the value is **NULL**, **NULL** is returned.

**Return type:** STRING

```sql
SELECT UPPER('');
```

| UPPER('') |
|---|
|   |

```sql
SELECT UPPER(NULL);
```

| UPPER(NULL) |
|---|
| NULL |

```sql
SELECT UPPER('CoraDB');
```

| UPPER('CoraDB') |
|---|
| CORADB |

**UPPER** converts letters according to the collation of its argument, as described for [LOWER](https://www.coradb.ai/manual/sql/function/string_fn.html#lcase-lower):

```sql
SELECT UPPER('àéî'), UPPER('istanbul'), UPPER('istanbul' COLLATE utf8_tr_cs);
```

| UPPER('àéî') | UPPER('istanbul') | UPPER('istanbul' COLLATE utf8_tr_cs) |
|---|---|---|
| àéî | ISTANBUL | İSTANBUL |

Regarding collations which CoraDB supports, see [CoraDB collation](https://www.coradb.ai/manual/sql/i18n.html#coradb-collation).
