CHAR


Returns a single text character, given a character code.

Syntax:

CHAR(number)

number is the character code, in the range 1-255.

CHAR system's character mapping (for example iso-8859-1, iso-8859-2, Windows-1252, Windows-1250) to determine which character to return. Codes greater than 127 may not be portable.

Example:

CHAR(72)

returns H, representing character code 72.


Application:

Converting ASCII Codes to Characters


Scenario: You have a table that stores user input for a security questionnaire. One column, Answer Code, stores a numerical code representing the user's selected option. You need to create a report that displays the actual character response, not just the code.


Table: User Responses

User ID

Question ID

Answer Code

User Answer

A
B
C
D
1
101
5
89
Y
2
102
5
78
N
3
103
5
78
N
4
104
5
89
Y
5
105
5
65
A

Explanation:

  • The CHAR(Answer Code) function takes the numerical value from the Answer Code column for each row.
  • It then looks up that number in the character set (in this case, the ASCII table).
  • It returns the corresponding character ('Y' for 89, 'N' for 78, and 'A' for 65) in a new column aliased as User Answer.




This page is protected by Google reCAPTCHA. Privacy - Terms.
 
Built using Zapof