简体   繁体   English

调用存储过程给出了错误

[英]calling stored procedure is giving an error

The error mysql is throwing is mysql抛出的错误是

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 1 检查与您的MySQL服务器版本相对应的手册,以在第1行的'NULL'附近使用正确的语法

My using phpmyadmin to wreite procedures. 我用phpmyadmin写程序。

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 ; 并且您可能会错过将分隔符设置为不同于;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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