简体   繁体   中英

calling stored procedure is giving an error

The error mysql is throwing is

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 'NULL' at line 1

My using phpmyadmin to wreite procedures.

and my stored procedure is

BEGIN
DECLARE page_limit int(100);
DECLARE page_no VARCHAR(100);
DECLARE rstarts int(100) DEFAULT 1;
DECLARE rends int(100) DEFAULT 15; 
DECLARE query varchar(255) ;

set query = ' select brandid from brandinfo limit @rstarts,@rends';
PREPARE stmt FROM @query; 
set rstarts =  15;
set rends =1;
EXECUTE stmt using @rstarts,@rends;
DEALLOCATE PREPARE stmt;
END

Declared variables and variables beginning with @ are two different stories. Read about user defined variables (the ones with @).

DELIMITER $$
CREATE PROCEDURE your_procedure_name()
BEGIN
SET @rstarts = 1;
SET @rends = 15; 

set @query = 'select brandid from brandinfo limit ?, ?';
PREPARE stmt FROM @query; 
EXECUTE stmt using @rstarts, @rends;
DEALLOCATE PREPARE stmt;
END $$
DELIMITER ;

Also in your query string you want to use ? as parameters, not the variable names. And you might miss on setting the delimiter to something different than ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM