Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite char, ascii function

Tags:

sql

sqlite

Is there any work around in sqlite to cover for the lack of "char()" and "ascii()" function ?

For example:

char(97) => 'a'
ascii('a') => 97
like image 411
w00d Avatar asked Jul 22 '12 23:07

w00d


2 Answers

I know this is too late but:

SELECT unicode('a') --ascii('a')
SELECT char(97)     --char(97)

I hope this helps :)

like image 84
Yashar Aliabbasi Avatar answered Sep 22 '22 23:09

Yashar Aliabbasi


Since the time this question was written, SQLite has evidently added a CHAR() function:

SELECT CHAR(97) -- Result is 'a'

However, the closest I've gotten in the other direction is with the HEX() function:

SELECT HEX('a') -- Result is 61 (hexadecimal, is equal to 97 decimal)

Obtaining a decimal ASCII character value seems like it'd require some convoluted work...

like image 27
Andres Cabezas Ulate Avatar answered Sep 18 '22 23:09

Andres Cabezas Ulate