Does Mysql have an equivalent to @@ROWCOUNT like in mssql?

后端 未结 5 1591
情深已故
情深已故 2020-11-27 05:05

How can I get row count values in MySQL as @@ROWCOUNT does in mssql?

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 05:44

    For SELECTs you can use the FOUND_ROWS construct (documented here):

    SELECT SQL_CALC_FOUND_ROWS something FROM your_table WHERE whatever;
    SELECT FOUND_ROWS( ) ;
    

    which will return the number of rows in the last SELECT query (or if the first query has a LIMIT clause, it returns the number of rows there would've been without the LIMIT).

    For UPDATE/DELETE/INSERT, it's the ROW_COUNT construct

    INSERT INTO your_table VALUES (1,2,3);
    SELECT ROW_COUNT();
    

    which will return the number of affected rows.

提交回复
热议问题