1.mysql 更新操作误用and
出处:https://www.jianshu.com/p/b455962b68a1
今天一个开发反馈update某行但不生效,场景如下:
mysql> select * from test; +------+------+ | c1 | c2 | +------+------+ | 0 | a | +------+------+
他想将c1列的值改成1、c2的值改成'b',然后用了如下sql:
update test set c1=1 and c2='b' where c1=0;
可以发现这个sql写法是错误的,正确写法应该是:update test set c1=1,c2='b' where c1=0;
但第一个错误的sql运行没报错,因为被MySQL理解成: update test set c1=(1 and c2='b') where c1=0; => update test set c1=(1 and 0) where c1=0; ==> update test set c1=0 where c1=0;
所以错误的sql相当啥都不做,但不仔细观察and应该改成逗号,还会觉得蛮诡异呢~
2.mybatis 批量删除
int delete(String[] usernos);
DELETE FROM USER WHERE USERNO IN #{userno,jdbcType.VARCHAR}
3.mybatis 更新
12 UPDATE USER3 4 7 WHERE8 USERNO = #{userno,jdbcType=VARCHAR}9LOGINNAME = #{loginName,jdbcType=VARCHAR}, 5PASSWORD = #{password,jdbcType=VARCHAR}, 6
4.other
1 2 13 14 25 26 34 3536 INSERT INTO USER37 (USERNO,IDTYPE,IDNUMBER,STATUS,BANKNO,LOGINNAME,PASSWORD,GENDER)38 VALUES39 (#{userno,jdbcType=VARCHAR},40 #{idType,jdbcType=CHAR},41 #{idNumber,jdbcType=VARCHAR},42 #{status,jdbcType=CHAR},43 #{bankNo,jdbcType=VARCHAR},44 #{loginName,jdbcType=VARCHAR},45 #{password,jdbcType=VARCHAR},46 #{gender,jdbcType=CHAR})47 48