Skip to content

ASCII

Given a character string, return the ASCII code value, an integer, for the first character in the string.

ASCII (string)

For UTF-8 characters, the function returns an integer that corresponds to the Unicode code point.

To get the ASCII code value or Unicode code point of an integer, use the CHR function.

Examples

Return the code value for the exclamation mark character:

premdb=# select ascii('!') from sys.const;
 ascii 
-------
   33
(1 row)

Return code values for a set of character strings in a table:

premdb=# select *, ascii(nickname) from team where city='London' order by ascii;
 teamid | htid | atid |        name         |  nickname  |  city  |     stadium      | capacity | avg_att | ascii 
--------+------+------+---------------------+------------+--------+------------------+----------+---------+-------
    12 |   13 |   62 | Charlton Athletic   | Addicks    | London | The Valley       |    27111 |   0.000 |    65
    18 |   19 |   68 | Fulham              | Cottagers  | London | Craven Cottage   |    25700 |   0.000 |    67
    46 |   47 |   96 | Wimbledon           | Dons       | London | Selhurst Park    |    26255 |   0.000 |    68
    15 |   16 |   65 | Crystal Palace      | Eagles     | London | Selhurst Park    |    26255 |  24.636 |    69
     1 |    2 |   51 | Arsenal             | Gunners    | London | Emirates Stadium |    60260 |  59.944 |    71
    44 |   45 |   94 | West Ham United     | Hammers    | London | Upton Park       |    35016 |  34.910 |    72
    32 |   33 |   82 | Queens Park Rangers | Hoops      | London | Loftus Road      |    18439 |   0.000 |    72
    13 |   14 |   63 | Chelsea             | Pensioners | London | Stamford Bridge  |    41663 |  41.500 |    80
    41 |   42 |   91 | Tottenham Hotspur   | Spurs      | London | White Hart Lane  |    36284 |  35.776 |    83
(9 rows)