程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> mysql 存儲過程的問題

mysql 存儲過程的問題

編輯:關於MYSQL數據庫
一開始用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官方發過郵件,同樣沒答復。現今只能求助諸位高人。
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved