为什么我把age字段设置成varchar类型,
age原值是100
然后age = age +'22'是122,而不是 10022呢.
百思不得其解呀,高手帮一下,谢谢了...

解决方案 »

  1.   

    如果目的是连接字符串,可以尝试concat(age,'22')喵~~`
      

  2.   

    mysql也有类型自动转换。 时间就是一个例子
      

  3.   

    这是不会的,我才做了测试
    public class TestString {
    public static void main(String arg0[]){
    String temp = "100" ;
    String str= "12" ;
    temp = temp +str;
    System.out.println(temp);
    }
    }得到的是10012
      

  4.   

    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'
      

  5.   

    3楼....lz是在说...MySql...喵~``咕咕~~`喵~~``
      

  6.   

    在 MySQL 中 + 运算符的作用是数值相加,当两边是字符串时,与 Java 不同,MySQL 会将字符串自动转换成数值再完成数值相加,所以会得到 122 这个整数。如果想完成字符串连接,可以使用 MySQL 中的 CONCAT(str1,str2,...)。