MySQL内置函数-单行函数(进制换算函数)

herohope 2020-06-10

进制换算

conv(n,from_base,to_base)

例如:
 
mysql> select conv("a",16,2);  --意思就是 将16进制的‘a’转换成2进制的

+----------------+
| conv("a",16,2) |
+----------------+
| 1010           |
+----------------+
1 row in set (0.00 sec)
mysql> select ascii(‘a‘);
+------------+
| ascii(‘a‘) |
+------------+
|         97 |
+------------+
1 row in set (0.00 sec)

mysql> select bin(10);
+---------+
| bin(10) |
+---------+
| 1010    |
+---------+
1 row in set (0.00 sec)

mysql> select oct(10);
+---------+
| oct(10) |
+---------+
| 12      |
+---------+
1 row in set (0.00 sec)

mysql> select hex(10);
+---------+
| hex(10) |
+---------+
| A       |
+---------+
1 row in set (0.00 sec)

char(n,...) 返回由参数n,...对应的ascii代码字符组成的一个字串(参数是n,...是数字序列,null值被跳过

mysql> select char(77,121,83,81,‘76‘);
+-------------------------+
| char(77,121,83,81,‘76‘) |
+-------------------------+
| MySQL                   |
+-------------------------+
1 row in set (0.00 sec)

mysql> select char(77,77.5,‘77.3‘);
+----------------------+
| char(77,77.5,‘77.3‘) |
+----------------------+
| MNM                  |
+----------------------+
1 row in set, 1 warning (0.00 sec)

相关推荐