update tablename set col1 = 'asdf' 
where id < 1000执行完上面这句话,影响行数是999行。
但我怎么样才能将999 赋值给指定的变量呢?

解决方案 »

  1.   

    楼上正解
    ROW_COUNT()返回前一个SQL进行UPDATE,DELETE,INSERT操作所影响的行数。
      

  2.   

    select的影响行数
    FOUND_ROWS() 
    update delete insert的影响行数
    ROW_COUNT()  
      

  3.   

    SET varName = ROW_COUNT();
      

  4.   

    mysql> update tablename set col1 = 'asdf' 
    where id < 1000;
    Query OK, 5 rows affected
    Rows matched: 5  Changed: 5  Warnings: 0mysql> set @a=row_count();
    Query OK, 0 rows affectedmysql> select @a;
    +----+
    | @a |
    +----+
    |  5 |
    +----+
    1 row in set