这是不会的,我才做了测试 public class TestString { public static void main(String arg0[]){ String temp = "100" ; String str= "12" ; temp = temp +str; System.out.println(temp); } }得到的是10012
concat(age, '22')是正解 顺便贴一段这个函数的描述 CONCAT(str1,str2,...) Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are non-binary strings, the result is a non-binary string. 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);CONCAT() returns NULL if any argument is NULL. mysql> SELECT CONCAT('My', 'S', 'QL'); -> 'MySQL' mysql> SELECT CONCAT('My', NULL, 'QL'); -> NULL mysql> SELECT CONCAT(14.3); -> '14.3'
3楼....lz是在说...MySql...喵~``咕咕~~`喵~~``
在 MySQL 中 + 运算符的作用是数值相加,当两边是字符串时,与 Java 不同,MySQL 会将字符串自动转换成数值再完成数值相加,所以会得到 122 这个整数。如果想完成字符串连接,可以使用 MySQL 中的 CONCAT(str1,str2,...)。
public class TestString {
public static void main(String arg0[]){
String temp = "100" ;
String str= "12" ;
temp = temp +str;
System.out.println(temp);
}
}得到的是10012
顺便贴一段这个函数的描述
CONCAT(str1,str2,...) Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are non-binary strings, the result is a non-binary string. 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);CONCAT() returns NULL if any argument is NULL. mysql> SELECT CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> SELECT CONCAT('My', NULL, 'QL');
-> NULL
mysql> SELECT CONCAT(14.3);
-> '14.3'