Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cursor row count

Tags:

sql

mysql

cursor

I'm writing a function in sql.

BEGIN
declare len int default 0;
declare other variables;

declare myCursor cursor for *myquery*;
set len = ? // cursor's length


RETURN -1;
END

I need the number of rows in the cursor's result, because the continuance of the function depends on the length.

I've tried @@CURSOR_ROWS, but it gave me: "MySQL said: #1193 - Unknown system variable 'CURSOR_ROWS'"

can anyone help me?

like image 852
AntonCool Avatar asked Sep 05 '26 23:09

AntonCool


1 Answers

The answer is:

select FOUND_ROWS() into len;
like image 138
AntonCool Avatar answered Sep 07 '26 17:09

AntonCool



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!