Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7501145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:26:23+00:00 2026-05-29T20:26:23+00:00

I am getting syntax error on runnning this. Is it possible to use variables

  • 0

I am getting syntax error on runnning this. Is it possible to use variables with limit without using concat function?

CREATE PROCEDURE SP(_start INT,_end INT)
BEGIN
     DECLARE _qry VARCHAR(500) DEFAULT CONCAT('select * from tbl limit ',_start,_end);
     PREPARE stmt FROM _qry;
 EXECUTE stmt;
 DEALLOCATE PREPARE stmt;
END

Error is

Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL     server version for the right syntax to use near '_qry;
 EXECUTE stmt;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:26:25+00:00Added an answer on May 29, 2026 at 8:26 pm

    I think you have to change the DEFAULT DELIMITER first and adding PARAMETER DIRECTION before creating the STORED PROCEDURE.

    There are good reasons to use prepared statements:
    1. ) Save on query parsing
    2.) Save on data conversion and copying
    3.) Avoid SQL Injection
    4.) Save memory on handling blobs
    
    There are also drawbacks and chewats of using prepared statements:
    
    1.) Query cache does not work
    2.) Extra server round trip required if statement used only once
    3.) Not all statements can be prepared. So you can’t use prepared API 
        exclusively you’ll need to fall back to normal API for some statements
    4.) Newer and sometimes buggy code. I had a lot of problems with PHP 
        prepared statements. It is getting better but still it is less mature 
        than standard API
    5.) You can’t use placeholders in place of all identifiers. For example you 
        can’t use them for table name. In certain version it even does not work for 
        LIMIT boundaries
    6.) Inconvenient list handling. Unlike in for example PEAR emulated prepard 
        statements there is no nice way to pass list of values to IN
    7.) Harder tracing. Logs were now fixed to include full statement text not 
        only “Execute” but in SHOW INNODB STATUS you would still see statements 
        without actual values – quite inonvenient for analyses.
    

    try this one:

    UPDATE 1

    DELIMITER $$
    
    CREATE PROCEDURE SP(IN _start INT,IN _end INT)
    
    BEGIN
    
         SET @iQuery = CONCAT('select * from tbl limit ', _start, ',', _end);
    
         PREPARE stmt FROM @iQuery;
         EXECUTE stmt;
         DEALLOCATE PREPARE stmt;
    
    END $$
    
    DELIMITER ;
    

    MySQL Syntax for Prepared Statements

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using this code <a onclick=javascript:var t=setInterval(GetUpdates(5,ajaxResult),300);>GetUpdates</a> but getting the syntax error
I'm getting syntax error in firebug here is the code : $('#moderator-attention').live('toogle', function(){ function
I'm using the TreeView control in Maya 2009 but I'm getting a syntax error
I'm getting a strange syntax error when I run this in VB: SQLString =
I'm getting this error whenever I attempt to declare a class: Parse error: syntax
I am getting this error: DataError: (DataError) invalid input syntax for integer: 1.50 CONTEXT:
I am getting syntax error with the following statement REPLACE INTO users (screenname, token,
Hey guys! I keep getting a syntax error (unexpected $end), and I've isolated it
I'm getting the following error on the line of code below: Syntax error (missing
I am getting this unfamiliar error when running the code bellow. I can't see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.