Skip to main content

ascii

1. ASCII Function

The ASCII function in H2 database is used to retrieve the ASCII value of the first character in a given string.

2. Syntax

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

ASCII(str)

Arguments

  • str: The string from which the ASCII value of the first character needs to be retrieved. It should be a string or a character literal.

Return

  • The ASCII function returns an integer representing the ASCII value of the first character in the given string.

3. Notes

  • The ASCII function in H2 database only considers the first character of the string and ignores the rest.
  • If the input string is empty, the ASCII function will return 0.
  • If the input string contains multibyte characters, the ASCII function will return the ASCII value of the first byte.

4. Examples

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

Example 1 - Retrieving the ASCII value of a character:

SELECT ASCII('A') AS ascii_value;

Output:

ascii_value
-----------
65

Example 2 - Retrieving the ASCII value of the first character in a string:

SELECT ASCII('Hello') AS ascii_value;

Output:

ascii_value
-----------
72

Example 3 - Retrieving the ASCII value of the first character in a column:

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

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

SELECT id, word, ASCII(word) AS ascii_value
FROM words;

Output:

id | word  | ascii_value
---+-------+------------
1 | Hello | 72
2 | World | 87
  • char - Convert ASCII value to character
  • UNICODE - Retrieve the Unicode value of a character