<<<<<<< HEAD stringtoutf8 | H2 | SQLDoc
Skip to main content

stringtoutf8

1. STRINGTOUTF8 Function

======= stringtoutf8 | H2 Function | SQLDoc

stringtoutf8

1. STRINGTOUTF8 Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The STRINGTOUTF8 function in H2 database is used to convert a string to its corresponding UTF-8 encoded representation.

2. Syntax

The syntax for the STRINGTOUTF8 function in H2 database is as follows:

STRINGTOUTF8(string)

Arguments

  • string: The string that needs to be converted to UTF-8 encoding. It should be a character string or a column of character data type.

Return

  • The STRINGTOUTF8 function returns the UTF-8 encoded representation of the input string.

3. Notes

  • The STRINGTOUTF8 function in H2 database converts the input string to its equivalent byte array in UTF-8 encoding.
  • If the input string contains characters that are not supported in UTF-8 encoding, the function may produce unexpected results.
  • It is important to note that the output of the STRINGTOUTF8 function is not a string but a byte array.

4. Examples

Here are a few examples demonstrating the usage of the STRINGTOUTF8 function in H2 database:

Example 1 - Converting a string to UTF-8 encoding:

SELECT STRINGTOUTF8('Hello World') AS utf8_string;

Output:

utf8_string
-------------------
48656C6C6F20576F726C64

Example 2 - Converting a column of strings to UTF-8 encoding:

CREATE TABLE words (
id INT PRIMARY KEY,
word VARCHAR(20)
);

INSERT INTO words VALUES (1, 'Hello'), (2, 'World');

SELECT id, word, STRINGTOUTF8(word) AS utf8_string
FROM words;

Output:

id | word  | utf8_string
---+-------+-------------------
1 | Hello | 48656C6C6F
2 | World | 576F726C64
  • utf8tostring - Convert UTF-8 encoded byte array to a string.