MySQL Forums
Forum List  »  Stored Procedures

Re: Variable in LIMIT clause
Posted by: Joss
Date: July 15, 2005 05:37AM

Markus Popp wrote:
> Looks interesting ;-), thanks!
>
> Is it possible to assign a variable to the second
> parameter of the LIMIT clause? Which can be used
> like
>
> SELECT ... LIMIT x, y
>
> That would be perfekt.
>
> Markus
>

Hi Markus,

Since I needed only a "LIMIT 0,n" use I haven't searched that much, but I guess you can still use your primary id with something like that:
CREATE PROCEDURE TestLIMIT` (IN offset INT, IN nbRowsToFetch INT)
BEGIN

SET SQL_SELECT_LIMIT = nbRowsToFetch;

SELECT * FROM myTable m
WHERE m.id > offset ;

SET SQL_SELECT_LIMIT = DEFAULT;

END\\

Otherwise you might like to play a bit with a CURSOR ;-)
Cheers,

Joss

Options: ReplyQuote


Subject
Views
Written By
Posted
44529
June 01, 2005 07:13PM
18421
June 13, 2005 06:34PM
14618
July 12, 2005 03:59PM
12616
July 13, 2005 05:57PM
10752
July 13, 2005 05:58AM
10450
July 12, 2005 04:07PM
Re: Variable in LIMIT clause
12084
July 15, 2005 05:37AM
8529
July 13, 2005 10:09AM
7933
July 15, 2005 05:45AM
8640
March 24, 2006 04:48PM
6547
June 15, 2006 07:23PM
6358
April 04, 2007 08:56PM
6714
April 11, 2007 01:07PM
14942
April 11, 2007 03:56PM
6788
May 02, 2007 11:28AM
5879
March 16, 2009 05:58PM
6479
March 16, 2009 07:21PM
7839
April 29, 2009 05:31PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.