时间:2021-05-24
一开始用phpMyAdmin来执行,后来出现一堆错误,后来去掉了begin,end之后可以正常执行,但要执行存储过程,在phpMyAdmn中不行,而在mysql命令行文本框中就可以。
接下来又遇到更难的问题,在存储过程中加入预处理语句,更不行了,在mysql命令行文本框下执行同样,下面的运行记录,给大家参考,能否有高手来帮助。
复制代码 代码如下:
mysql> CREATE PROCEDURE catalog_get_products_in_category(
-> IN inCategoryId INT, IN inShortProductDescriptionLength INT,
-> IN inProductsPerPage INT, IN inStartItem INT)
-> begin
-> SELECT p.product_id, p.name,IF(LENGTH(p.description) <= inShortProductD
escriptionLength, p.description,
-> CONCAT(LEFT(p.description, inShortProductDescriptionLength),'...')) AS
description, p.price, p.discounted_price, p.thumbnail
-> FROM product p INNER JOIN product_category pc ON p.product_id = pc.pro
duct_id
-> WHERE pc.category_id = inCategoryId
-> ORDER BY p.display DESC
-> LIMIT inStartItem;inProductsPerPage;
-> end$$
ERROR 1064 (42000): 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 'inSta
rtItem;inProductsPerPage;
end' at line 10
//原本的存储过程语句
EATE PROCEDURE catalog_get_products_in_category(
IN inCategoryId INT, IN inShortProductDescriptionLength INT,
IN inProductsPerPage INT, IN inStartItem INT)
BEGIN
PREPARE statement FROM
"SELECT p.product_id, p.name,IF(LENGTH(p.description) <= ?, p.description,
CONCAT(LEFT(p.description, ?),'...')) AS description, p.price, p.discounted_price, p.thumbnail
FROM product p INNER JOIN product_category pc ON p.product_id = pc.product_id
WHERE pc.category_id = ?
ORDER BY p.display DESC
LIMIT ?, ?";
SET @p1 = inShortProductDescriptionLength;
SET @p2 = inShortProductDescriptionLength;
SET @p3 = inCategoryId;
SET @p4 = inStartItem;
SET @p5 = inProductsPerPage;
EXECUTE statement USING @p1, @p2, @p3, @p4, @p5;
END$$
mysql> delimiter $$
mysql> CREATE PROCEDURE catalog_get_products_in_category(
-> IN inCategoryId INT, IN inShortProductDescriptionLength INT,
-> IN inProductsPerPage INT, IN inStartItem INT)
-> BEGIN
-> PREPARE statement FROM
-> "SELECT p.product_id, p.name,IF(LENGTH(p.description) <= ?, p.descript
ion,
"> CONCAT(LEFT(p.description, ?),'...')) AS description, p.price, p.disco
unted_price, p.thumbnail
"> FROM product p INNER JOIN product_category pc ON p.product_id = pc.pro
duct_id
"> WHERE pc.category_id = ?
"> ORDER BY p.display DESC
"> LIMIT ?, ?";
-> SET @p1 = inShortProductDescriptionLength;
-> SET @p2 = inShortProductDescriptionLength;
-> SET @p3 = inCategoryId;
-> SET @p4 = inStartItem;
-> SET @p5 = inProductsPerPage;
-> EXECUTE statement USING @p1, @p2, @p3, @p4, @p5;
-> END$$
ERROR 1314 (0A000): PREPARE is not allowed in stored procedures
上面有两个存储过程,一个不用预处理语句,一个用了预处理语句,
之后,向作者发过邮件,没有答复,又给mysql官方发过邮件,同样没答复。现今只能求助诸位高人。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
MySQL存储过程14.1.1创建存储过程MySQL中,创建存储过程的基本形式如下:CREATEPROCEDUREsp_name([proc_parameter
MySQL存储过程参数有三种类型:in、out、inout。它们各有什么作用和特点呢?一、MySQL存储过程参数(in)MySQL存储过程“in”参数:跟C语言
一、MySQL存储过程参数(in)MySQL存储过程“in”参数:跟C语言的函数参数的值传递类似,MySQL存储过程内部可能会修改此参数,但对in类型参数的修改
mysql在5.1之后增加了存储过程的功能,存储过程运行在mysql内部,语句都已经编译好了,速度比sql更快.存储过程与mysql相当于shell和linux
本文实例讲述了mysql存储过程原理与用法。分享给大家供大家参考,具体如下:本文内容:什么是存储过程存储过程的创建存储过程的使用查看存储过程修改存储过程删除存储