updaate tab set coll = substring(coll,1,10) + "abc"; 这样怎算?
SUBSTRING(str,pos,len) Returns a substring len characters long from string str, starting at position pos. mysql> SELECT SUBSTRING('Quadratically',5,6); -> 'ratica'SUBSTRING(str,pos) Returns a substring from string str starting at position pos: mysql> SELECT SUBSTRING('Quadratically',5); -> 'ratically'update tab set coll = substring(coll,1,10) + abc'; 从coll的1个字符开始取10个字符,加上'abc',再写入coll中,如果coll原始值为'1234567890XYZ',则更新之后为'1234567890abc'了。更多函数见:http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#String_functions
sorry, 我凭感觉写的,没在MYSQL上测试。MYSQL我用的并不多,不过既然innodb是建表时指定的,应该与它无关。可能MYSQL对string类型不支持'+'运算符,用concat()试试。update tab set coll = concat(substring(coll,1,10),'abc');CONCAT(str1,str2,...) Returns the string that results from concatenating the arguments. Returns NULL if any argument is NULL. May have more than 2 arguments. A numeric argument is converted to the equivalent string form: mysql> SELECT CONCAT('My', 'S', 'QL'); -> 'MySQL' mysql> SELECT CONCAT('My', NULL, 'QL'); -> NULL mysql> SELECT CONCAT(14.3); -> '14.3'
这样怎算?
Returns a substring len characters long from string str, starting at position pos.
mysql> SELECT SUBSTRING('Quadratically',5,6);
-> 'ratica'SUBSTRING(str,pos)
Returns a substring from string str starting at position pos:
mysql> SELECT SUBSTRING('Quadratically',5);
-> 'ratically'update tab set coll = substring(coll,1,10) + abc';
从coll的1个字符开始取10个字符,加上'abc',再写入coll中,如果coll原始值为'1234567890XYZ',则更新之后为'1234567890abc'了。更多函数见:http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#String_functions
为'1234567890XYZ',则更新之后为'abc'了。
为什么呢,我用的INNODB;
Returns the string that results from concatenating the arguments. Returns NULL if any argument is NULL. May have more than 2 arguments. A numeric argument is converted to the equivalent string form:
mysql> SELECT CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> SELECT CONCAT('My', NULL, 'QL');
-> NULL
mysql> SELECT CONCAT(14.3);
-> '14.3'