The ASCII function in MySQL returns the ASCII character code corresponding to the first character in the provided input string.
Example for using the ASCII function
CREATE FUNCTION ascii_string (in_string VARCHAR(80) ) RETURNS VARCHAR(256) DETERMINISTIC BEGIN DECLARE i INT DEFAULT 1; DECLARE string_len INT; DECLARE out_string VARCHAR(256) DEFAULT ''; SET string_len=LENGTH(in_string); WHILE (i<string_len) DO SET out_string=CONCAT(out_string,ASCII(SUBSTR(in_string,i,1)),' '); SET i=i+1; END WHILE; RETURN (out_string); END
Executing the function
>SELECT ascii_string('MySQL Rocks!') +---------------------------------------+ | ascii_string('MySQL Rocks!') | +---------------------------------------+ | 77 121 83 81 76 32 82 111 99 107 115 | +---------------------------------------+ 1 row in set (0.00 sec)