MySQL 如何在mysql中连接整数(整数与整数)和varchar(varchar与varchar)等数据类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2479012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to concat datatypes like integers(integer with integer) & varchar(varchar with varchar) in mysql?
提问by Rachel
How can we concat
我们如何连接
- integers with integers
- varchar with varchar
- int with varchar
- 整数与整数
- varchar 与 varchar
- 带 varchar 的 int
in MySQL ?
在 MySQL 中?
回答by nickf
Use CONCAT
用 CONCAT
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_concat
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_concat
SELECT CONCAT(1, 2);
-- "12"
SELECT CONCAT('foo', 'bar');
-- "foobar"
SELECT CONCAT(1, 'bar');
-- "1bar"
回答by MrM
if the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary string form; if you want to avoid that, you can use an explicit type cast, as in this example:
如果参数包含任何二进制字符串,则结果为二进制字符串。数字参数被转换为其等效的二进制字符串形式;如果要避免这种情况,可以使用显式类型转换,如下例所示:
SELECT CONCAT(CAST(int_col AS CHAR), char_col);
回答by user4702237
For two columns concatenation name: CHAR and no: int
对于两列串联名称:CHAR 和 no:int
PIG syntax is CONCAT(name,(CHARARRAY)no);
PIG 语法是 CONCAT(name,(CHARARRAY)no);