Oracle SQL - ASCII and CHR

Introduction

The following code illustrates the text functions ASCII and CHR.

If you compare the third and the fifth columns of the result, you can see that the ASCII function considers only the first character of its argument, regardless of the length of the input text.

Demo

SQL>
SQL> select ascii('a'), ascii('z')
  2  ,      ascii('A'), ascii('Z')
  3  ,      ascii('ABC'), chr(77)
  4  from   dual;

ASCII('A') | ASCII('Z') | ASCII('A') | ASCII('Z') | ASCII('ABC') | C
---------- | ---------- | ---------- | ---------- | ------------ | -
  00097.00 |   00122.00 |   00065.00 |   00090.00 |     00065.00 | M

SQL>-- from   w  w  w.j ava  2  s.  com

The first two column headings are very confusing, because SQL*Plus converts all SELECT clause expressions to uppercase, including your function arguments.

To show lowercase characters in your column headings, add column aliases and specify them between double quotes.

For example:

Demo

SQL>
SQL> select ascii('a') as "ASCII('a')", ascii('z') as "ASCII('z')"
  2

Related Topic