香港云主机最佳企业级服务商!

ADSL拨号VPS包含了中国大陆(联通,移动,电信,)

中国香港,国外拨号VPS。

当前位置:云主机 > MYSQL >

电信ADSL拨号VPS
联通ADSL拨号VPS
移动ADSL拨号VPS

mysql 存储过程的问题


时间:2020-11-02 13:25 作者:admin


一开始用phpMyAdmin来执行,后来出现一堆错误,后来去掉了begin,end之后可以正常执行,但要执行存储过程,在phpMyAdmn中不行,而在mysql/' target='_blank'>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官方发过邮件,同样没答复。现今只能求助诸位高人。 (责任编辑:admin)






帮助中心
会员注册
找回密码
新闻中心
快捷通道
域名登录面板
虚机登录面板
云主机登录面板
关于我们
关于我们
联系我们
联系方式

售前咨询:17830004266(重庆移动)

企业QQ:383546523

《中华人民共和国工业和信息化部》 编号:ICP备00012341号

Copyright © 2002 -2018 香港云主机 版权所有
声明:香港云主机品牌标志、品牌吉祥物均已注册商标,版权所有,窃用必究

云官方微信

在线客服

  • 企业QQ: 点击这里给我发消息
  • 技术支持:383546523

  • 公司总台电话:17830004266(重庆移动)
  • 售前咨询热线:17830004266(重庆移动)