一、拼接字符串
需求:account_code原来数据的基础上在其前添加‘HSJS’的标识……
1)误操作一:
mysql> update tbpayment_settlement set account_code = ('HSJS'+ account_code) where id = 616783;
1292 - Truncated incorrect DOUBLE value: 'HSJS'
mysql>
2)误操作二:
mysql> update tbpayment_settlement set account_code = ('1001'+ account_code) where id = 616783;
1292 - Truncated incorrect DOUBLE value: '201908'
mysql>
补充:
mysql> select account_code from tbpayment_settlement where id = 616783;
+--------------+
| account_code |
+--------------+
| 201908 |
+--------------+
1 row in set
mysql>
解答:account_code为varchar类型,不能采用 ‘+’ 来拼接字符串,‘+’ 用于数字类型的相加。而字符串应使用concat(str1,str2,...)函数。
3)正解
mysql> update tbpayment_settlement set account_code = concat('HSJS',account_code) where id = 616783;
Query OK, 1 row affected
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select account_code from tbpayment_settlement where id = 616783;
+----------------+
| account_code |
+----------------+
| HSJS201908 |
+----------------+
1 row in set
mysql>