登录
首页 >  数据库 >  MySQL

如何在 MySQL 中查找非 ASCII 字符?

来源:tutorialspoint

时间:2023-09-02 16:10:00 314浏览 收藏

各位小伙伴们,大家好呀!看看今天我又给各位带来了什么文章?本文标题《如何在 MySQL 中查找非 ASCII 字符?》,很明显是关于数据库的文章哈哈哈,其中内容主要会涉及到等等,如果能帮到你,觉得很不错的话,欢迎各位多多点评和分享!

非 ASCII 字符包括英镑符号 (£)、商标符号、加减号等字符 符号等。要从表中查找非 ASCII 字符,需要执行以下步骤 -

首先在 create 命令的帮助下创建一个表,如下所示 -

mysql> CREATE table NonASciiDemo
-> (
-> NonAScii varchar(100)
-> );
Query OK, 0 rows affected (0.61 sec)

之后,借助插入命令将记录插入表中,如下所示 如下 -

mysql> INSERT into NonASciiDemo values('-,-');
Query OK, 1 row affected (0.18 sec)

mysql> INSERT into NonASciiDemo values('  ');
Query OK, 1 row affected (0.23 sec)

mysql> INSERT into NonASciiDemo values('£');
Query OK, 1 row affected (0.30 sec)

mysql> INSERT into NonASciiDemo values('123abcd£');
Query OK, 1 row affected (0.24 sec)

如上所示,表中插入了四条记录,其中两条记录包含非 ASCII characters and two records contain ASCII characters.

To display allthe records, select command is used as 如下 -

SELECT * from NonASciiDemo;

以下是输出

+----------+
| NonAScii |
+----------+
| -,-      |
|          |
| £        |
| 123abcd£ |
+----------+
4 rows in set (0.00 sec)

The syntax to find the non ASCII characters is given as 如下 -

SELECT * FROM yourTableName WHERE NOT HEX(yourColumnName) REGEXP '^([0-7][0-
9A-F])*$';

The query to get the non ASCII characters using the above syntax is given as 如下 -

mysql> SELECT * FROM NonASciiDemo WHERE NOT HEX(NonAScii) REGEXP '^([0-7][0-9AF])*$';

以下是上述查询的输出 -

+----------+
| NonAScii |
+----------+
| £        |
| 123abcd£ |
+----------+
2 rows in set (0.00 sec)

本篇关于《如何在 MySQL 中查找非 ASCII 字符?》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于数据库的相关知识,请关注golang学习网公众号!

声明:本文转载于:tutorialspoint 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>