在 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/