loading..
Русский    English
02:34

ASCII and CHAR functions

Let's start from two reciprocally related functions - ASCII and CHAR.

The ASCII function returns an ASCII code value of the leftmost character of a character expression, being a function argument.

Here is an example of the way to determine how many different letters which the names of the ships in the Ships table start from are:

Console
Execute
  1. SELECT COUNT(DISTINCT ASCII(name))
  2. FROM Ships

The result is 11. To find out what these letters are, we can use CHAR function that returns a character by a known ASCII code value (from 0 to 255):

Console
Execute
  1. SELECT DISTINCT CHAR(ASCII(name))
  2. FROM Ships
  3. ORDER BY 1

We should note that the identical result can be got simpler using one more function - LEFT.

Bookmark and Share
The book was updated
yesterday
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.
Rambler's Top100