w3resource

Oracle ASCII function

Description

The ASCII() function returns the decimal representation of the first character of a character expression.

Character expression can be the following data types:

  • CHAR
  • VARCHAR2
  • NCHAR
  • NVARCHAR2

The function does not support CLOB data directly. However, CLOBs can be passed in as arguments through implicit data conversion.

Note : If your database character set is 7-bit ASCII, then this function returns an ASCII value. If your database character set is EBCDIC Code, then this function returns an EBCDIC value.

Uses of Oracle ASCII Function
  • Character to ASCII Conversion: Convert the first character of a string to its ASCII decimal value.

  • Filtering Data: Select records based on the ASCII value of characters, such as filtering names starting with a specific letter.

  • Character Encoding Analysis: Analyze character encoding by retrieving ASCII values of characters.

  • String Comparison: Compare strings based on the ASCII values of their characters for sorting or other operations.

Syntax:

ASCII(character_expression)

Parameters:

Name Description
character_expression Is an expression of the above data types mentioned in the list.

Return Value Type:

NUMBER.

Applies to:

Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Examples: Oracle ASCII function

The following example returns employees whose first names begin with the letter 'C', whose ASCII equivalent is 67:

SQL> SELECT first_name  FROM employees
  2  WHERE ASCII(SUBSTR(first_name, 1, 1)) = 67
  3  ORDER BY last_name;

Sample Output:

FIRST_NAME
--------------
Curtis
Charles
Christopher
Clara

Previous: UPPER
Next: INSTR



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/oracle/character-functions/oracle-ascii-function.php