你的位置:首页 > 软件开发 > 数据库 > MySQL 中的 FOUND_ROWS() 函数

MySQL 中的 FOUND_ROWS() 函数

发布时间:2015-09-18 12:00:11
移植sql server 的存储过程到mysql中,遇到了sql server中的:IF @@ROWCOUNT < 1对应到mysql中可以使用 FOUND_ROWS() 函数来替换。1. found_rows() 函数的文档:http://dev.mysql.com/do ...

MySQL 中的 FOUND_ROWS() 函数

移植sql server 的存储过程到mysql中,遇到了sql server中的:

IF @@ROWCOUNT < 1

对应到mysql中可以使用 FOUND_ROWS() 函数来替换。

1. found_rows() 函数的文档:

http://dev.mysql.com/doc/refman/5.6/en/information-functions.html#function_found-rows

1)found_rows() 的第一种使用情况(带有SQL_CALC_FOUND_ROWS,也带 limit):

A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward:

mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name  -> WHERE id > 100 LIMIT 10;mysql> SELECT FOUND_ROWS();

The second SELECT returns a number indicating how many rows the first SELECT would have returned had it been written without the LIMIT clause.

前面的带有limit的select语句如果加上了 SQL_CALC_FOUND_ROWS,那么接下来执行的 SELECT FOUND_ROWS(); 将返回前面语句不带limit语句返回的行数

原标题:MySQL 中的 FOUND_ROWS() 函数

关键词:MYSQL

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。