Limit in MySQL stored procedure

Source: Internet
Author: User

1, high version of MySQL (5.5), the stored procedure limit can use variables, as follows: SELECT * from student limit istart,inum;

2, the low version of MySQL (5.1), stored in the process of limit can not use variables, compile error, as follows: You have a error in your SQL syntax, ... near Istart,inum

3, how to solve the problem of the low version?

drop PROCEDURE IF EXISTS ' dmu_exedynamicsql_bypage ';
delimiter;;
create definer= ' root ' @ '% ' PROCEDURE ' dmu_exedynamicsql_bypage ' (_qrysql Mediumtext, out _totalcount int)
begin
set @qrySql = _qrysql;
prepare stmt from @qrySql;
execute stmt;
deallocate prepare stmt;--Release preprocessing segment

Set _totalcount = 0;
Select Found_rows () into _totalcount;
END
;;
DELIMITER;

Note: DELIMITER; The meaning. Default semicolon in MySQL; Is the end of an execution, and the stored procedure contains multiple statements, semicolon intervals, which are executed together, how to solve the problem?

DELIMITER;;  Tell MySQL to execute the following statement together until it encounters two semicolons;; After the above stored procedure executes, DELIMITER; Switch the delimiter to a single semicolon;

Limit in MySQL stored procedure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.