如何在MySQL中返回静态字符串?
为了在MySQL中返回静态字符串,可以使用UNION。以下是其语法 –
select 'yourStringValue1' as yourAliasName
UNION
select 'yourStringValue2' as yourAliasName;
让我们实现上述语法以在MySQL中返回静态字符串。以下是查询 –
mysql> select 'HELLO' as staticStringsResult
-> UNION
-> select 'MySQL' as staticStringsResult;
这将产生以下输出 –
+---------------------+
| staticStringsResult |
+---------------------+
| HELLO |
| MySQL |
+---------------------+
2 rows in set (0.00 sec)
在某些MySQL版本中,上述语法不起作用,因此您需要用括号包住它 –
mysql> (select 'HELLO' as staticStringsResult)
-> UNION
-> (select 'MySQL' as staticStringsResult);
这将产生以下输出 –
+---------------------+
| staticStringsResult |
+---------------------+
| HELLO |
| MySQL |
+---------------------+
2 rows in set (0.00 sec)
阅读更多:MySQL 教程
极客教程