Home >Database >Mysql Tutorial >MySQL ASCII()函数返回字符的ASCII码值

MySQL ASCII()函数返回字符的ASCII码值

WBOY
WBOYOriginal
2016-06-01 09:56:554211browse

ASCII(str1)

返回字符串str的最左面字符的ASCII代码值。如果str是空字符串,返回0。如果str是NULL,返回NULL

举例:

1.

<code class="language-sql">mysql> select ascii('hi');
+————-+
| ascii('hi') |
+————-+
|         104 |
+————-+
1 row in set</code>

104是h的ASCII值

 

2.输出b和B的ASCII值

<code class="language-sql">mysql> SELECT ASCII('b')AS Lower_Case, ASCII('B') AS Upper_Case;
+————+————+
| Lower_Case | Upper_Case |
+————+————+
|         98 |         66 |
+————+————+
1 row in set</code>

 

3.在where语句中使用ASCII函数

输出aut_name首字母的ASCII值小于70的数据

<code class="language-sql">SELECT aut_name,ASCII(aut_name)as "ASCII value of 1st character"   
FROM author   
WHERE ASCII(aut_name)</code>

 

4.输出字段中不存在没有ASCII值的数据

<code class="language-sql">SELECT * FROM table_name WHERE NOT column_to_check REGEXP '[A-Za-z0-9.,-]';</code>

 

5.与SUBSTRING一起使用计算字符串第二个以后的ASCII值

<code class="language-sql">mysql> select ASCII(SUBSTRING('database',2,1));
+———————————-+
| ASCII(SUBSTRING('database',2,1)) |
+———————————-+
|                               97 |
+———————————-+
1 row in set</code>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn