update 表 set 字段 = 'http://' + 字段内容 where 条件比如某字段内容为123123,我想update为http://123123这代码在MSSQL可以正常update,但是MYSQL update以后那个字段就成了 0 。请问应该如何做?

解决方案 »

  1.   

    update 表 set 字段=concat('http://',字段) where 条件;
    前提,你的字段是字符型, 字符串合并默认情况下用CONCAT(),这个和其它数据库不太一样。
    mysql> select * from t5 where id=20;
    +------+--------+
    | id   | c1     |
    +------+--------+
    |   20 | 123123 |
    +------+--------+
    1 row in set (0.00 sec)mysql> update t5 set c1=concat('http://',c1)  where id=20;
    Query OK, 1 row affected (0.06 sec)
    Rows matched: 1  Changed: 1  Warnings: 0mysql> select * from t5 where id=20;
    +------+---------------+
    | id   | c1            |
    +------+---------------+
    |   20 | http://123123 |
    +------+---------------+
    1 row in set (0.00 sec)mysql>
    http://dev.mysql.com/doc/refman/5.1/zh/functions.html#string-functions
    12.3. 字符串函数
    CONCAT(str1,str2,...)                        
    返回结果为连接参数产生的字符串。如有任何一个参数为NULL ,则返回值为 NULL。或许有一个或多个参数。
    
      

  2.   

    看你的情况,你的字段的类型应该是int的,要先alter,把字段改称varchar类型。
      

  3.   

    update 表 set 字段 = concat('http://', 字段内容) where 条件