猿问

mysql连字符 || 的一个问题?

有一个表,名字是main,表内容如下:mysql>select*frommain;+------+----------+|ID|username|+------+----------+|0|user0||1|user1||2|user2|+------+----------+执行命令返回:mys...  有一个表,名字是main,表内容如下:
mysql> select * from main;
+------+----------+
| ID   | username |
+------+----------+
|    0 | user0    |
|    1 | user1    |
|    2 | user2    |
+------+----------+
执行命令返回:
mysql> select username from main where username='user0' || (select 1 from dual where (select username from main where username='user0')='user0');
+----------+
| username |
+----------+
| user0    |
| user1    |
| user2    |
+----------+

为什么会有这个结果?我从来没有在我的语句里面涉及user1和user2,顺便说一下,单独执行执行第二句select 1 from dual where (select username from main where username='user0')='user0'结果如下:
+---+
| 1 |
+---+
| 1 |
+---+  展开

翻翻过去那场雪
浏览 872回答 1
1回答

鸿蒙传说

mysql> select username from main where username='user0' || (select 1 from dual where (select username from main where username='user0')='user0');+----------+| username |+----------+| user0    || user1    || user2    |+----------+那个||是连接字符串,是Oracle 里面连接字符串的。MySQL 里面, 连接字符串是用  CONCAT  函数来连接的。如果你要连接字符串,那么='user0' || (select 1 from ..... )需要修改为=CONCAT('user0',(select1from.....))
随时随地看视频慕课网APP

相关分类

MySQL
我要回答