Mysql's limit offset cannot be followed by variables that can only be hard-coded.

Source: Internet
Author: User

I encountered a problem when writing the MySQL stored procedure today.

MySQL version: 5.1.40

I don't know if the higher version has this problem.

Skip this issue if the previous version does not exist.

 

The SQL statement is as follows:

Select PID, names into _ dp_id, _ dp_names from department limit 1 offset _ dp_count;

_ Dp_count is a variable I declare

 

An error is reported during execution...

 

 

Error code: 1064you have an error in your SQL syntax; check the manual that corresponds to your MySQL Server version for the right syntax to use near '_ dp_count;

 

The original MySQL limit and offset cannot be followed by the variable

 

The solution is to use Concat to combine SQL statements.

 

Then prepare and execute again.

 

 

 

I tried postgresql9.0.10. This problem does not exist.

 

 

 

I don't know if this problem occurs in other databases.

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.