mysql - 在SELECT子句中添加/连接文本值

时间:2010-10-14 05:02:54

标签: mysql mysqldump

MySQL是否有办法使用SELECT语句将文本连接到值? (就像在Oracle中一样)

例如,在Oracle中,您可以编写如下内容:

SQL> select 'The Year is '|| year, 'The month is '|| month from time where rownum < 2;

'THEYEARIS'||YEAR
----------------------------------------------------
'THEMONTHIS'||MONTH
-----------------------------------------------------
The Year is 2009
The month is 1

2 个答案:

答案 0 :(得分:15)

SELECT Concat(vend_name, ' (', vend_country, ')')
FROM vendors
ORDER BY vend_name;

阅读本教程:

http://www.brainbell.com/tutorials/MySQL/Concatenating_Fields.htm

答案 1 :(得分:3)

mysql中有CONCAT函数。

select concat('The Year is ', year), concat('The month is ', month) from time where rownum < 2;