mysql - 使用 mysql 命令行客户端选择时如何查看数据中的空格

标签 mysql sql

在 sql-command-line-client 中使用 select 时,如何查看字符串中的空格?

我的意思是下面的。你有三行。 1、2 和 3 个空格。 您没有机会看到空格数。

create table foo(bar varchar(8));
insert into foo values(" "),("  "), ("   ");

select * from foo\g
+------+
| bar  |
+------+
|      |
|      |
|      |
+------+

mysql> select * from foo\G
*************************** 1. row ***************************
bar:  
*************************** 2. row ***************************
bar:   
*************************** 3. row ***************************
bar:    
3 rows in set (0.01 sec)

我想到的唯一选择是:

mysql> select bar, hex(bar) from foo;
+------+----------+
| bar  | hex(bar) |
+------+----------+
|      | 20       |
|      | 2020     |
|      | 202020   |
+------+----------+
3 rows in set (0.01 sec)

php 中类似 var_export 的东西会很好。

最佳答案

似乎有一个字符串函数 QUOTE(转义参数以在 SQL 语句中使用)效果非常好。

-- to add another tricky example
mysql> insert into foo values(" \" ' "), ("''");
Query OK, 1 row affected (0.06 sec)

mysql> select bar, quote(bar) from foo;
+-------+------------+
| bar   | quote(bar) |
+-------+------------+
|       | ' '        |
|       | '  '       |
|       | '   '      |
|  " '  | ' " \' '   |
| ''    | '\'\''     |
+-------+------------+
4 rows in set (0.00 sec)

关于mysql - 使用 mysql 命令行客户端选择时如何查看数据中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15362001/

相关文章:

mysql - 当只有极限值时,获取中间的每个值

php - While 循环语法错误(无限循环)

MySQL。横向显示属性

mysql - 为什么这个查询这么慢?

php - 电话簿更新问题

创建具有 2 个外键作为主键的表时 MySQL 语法错误

mysql - 基于另一行的值的不同结果

sql - 如何在 MySQL 中执行 FULL OUTER JOIN?

sql - SQL Server Compact 是否支持多个返回案例参数

sql - 语法错误问题