1.ascii()函數返回字符串的第一個字符的ascii碼,參數爲字符串,若是不是,則會被強轉爲字符串形式函數
select ascii(123); +------------+ | ascii(123) | +------------+ | 49 | +------------+
123被當作"123"處理。"1"的ascii碼值爲49編碼
select ascii("咱們"); +-----------------+ | ascii("咱們") | +-----------------+ | 230 | +-----------------+
「我"的utf-8編碼值爲0xe68b91,取高位0xe6,十進制爲230spa
2.bin()函數返回參數的二進制表示,參數爲數值,若是不是數值,則會被強轉爲數值類型。參數以十進制整數形式表示code
select bin("12"); +-----------+ | bin("12") | +-----------+ | 1100 | +-----------+
字符串"12"被當作數值12處理blog
select bin("a"); +----------+ | bin("a") | +----------+ | 0 | +----------+
字符串"a"強轉爲數值類型,結果是0, utf-8
select bin("12a"); +------------+ | bin("12a") | +------------+ | 1100 | +------------+
字符串發生了數值截取ci
select bin("a12"); +------------+ | bin("a12") | +------------+ | 0 | +------------+
select bin(12.34); +------------+ | bin(12.34) | +------------+ | 1100 | +------------+
小數部分不參與轉換字符串
3.oct()函數返回參數的八進制表示,規則和bin()同樣class
4.hex()函數返回數值或者字符串的十六進制表示select
select hex(12); +---------+ | hex(12) | +---------+ | C | +---------+
select hex('12'); +-----------+ | hex('12') | +-----------+ | 3132 | +-----------+
select hex(12.34); +------------+ | hex(12.34) | +------------+ | C | +------------+
忽略小數部分
select hex('我'); +------------+ | hex('我') | +------------+ | E68891 | +------------+