Problems with MySQL stored procedures _mysql

Source: Internet
Author: User
Tags prepare mysql command line
Start with the phpMyAdmin to execute, and then a bunch of errors, then remove the begin,end can normally execute, but to execute the stored procedure, in phpmyadmn, and in the MySQL command line text box can.
The next encounter more difficult problems, in the stored procedure to add preprocessing statements, even worse, in the MySQL command line text box to execute the same, the following running records, for you to refer to, whether there is a master to help.
Copy Code code as follows:

Mysql> CREATE PROCEDURE catalog_get_products_in_category (
-> in Incategoryid int, 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 a 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 ' in line 10

The original stored procedure statement
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, 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 isn't allowed in stored procedures

There are two stored procedures, one without preprocessing statements, one with preprocessing statements,
After, sent an email to the author, no reply, and gave the MySQL official email, also no reply. Now I can only turn to you.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.