MySQL存储过程案例语句语法错误-续2

时间:2018-09-08 11:33:30

标签: mysql sql syntax-error

以下代码中的一个语法错误。 mysql的响应是

  

错误1064:您的SQL语法有错误;查看手册   对应于您的MySQL服务器版本的正确语法,   在'300ml','500ml','1lit','2lit'附近使用)   VALUES(m_cust_id,IN_book_id,(SELECT Rate.Can * Book'在第24行SQL   声明

以下是步骤。

CREATE PROCEDURE `calculate_amount` (in IN_book_id INT,  in IN_qty INT )
BEGIN
-- declare
DECLARE m_prdct VARCHAR(10);
DECLARE m_cust_id INT(5);

-- select into
SELECT 
    Product
FROM
    Bookings
WHERE
    Book_id = IN_book_id INTO m_prdct;

SELECT 
    Cust_id
FROM
    Bookings
WHERE
    Book_id = IN_book_id INTO m_cust_id;

-- conditionals & action
IF (m_prdct = '20ltr') THEN
INSERT INTO Amount (Cust_id,Book_id,Can,'300ml','500ml','1lit','2lit') VALUES(m_cust_id,IN_book_id,(SELECT Rate.Can*Bookings.Qty FROM Rate,Bookings WHERE Bookings.Book_id=IN_book_id),0,0,0,0); 

ELSEIF (m_prdct = '300ml') THEN
INSERT INTO Amount(Cust_id,Book_id,Can,'300ml','500ml','1lit','2lit') VALUES(m_cust_id,IN_book_id,0,(SELECT Rate.300ml*Bookings.Qty FROM Rate,Bookings WHERE Bookings.Book_id=IN_book_id),0,0,0);

ELSEIF (m_prdct = '500ml') THEN 
INSERT INTO Amount(Cust_id,Book_id,Can,'300ml','500ml','1lit','2lit') VALUES(m_cust_id,IN_book_id,0,0,(SELECT Rate.500ml*Bookings.Qty FROM Rate,Bookings WHERE Bookings.Book_id=IN_book_id),0,0); 

ELSEIF (m_prdct = '1ltr') THEN 
INSERT INTO Amount(Cust_id,Book_id,Can,'300ml','500ml','1lit','2lit') VALUES(m_cust_id,IN_book_id,0,0,0,(SELECT Rate.1lit*Bookings.Qty FROM Rate,Bookings WHERE Bookings.Book_id=IN_book_id),0); 

ELSE 
    INSERT INTO Amount(Cust_id,Book_id,Can,'300ml','500ml','1lit','2lit') VALUES(m_cust_id,IN_book_id,0,0,0,0,(SELECT Rate.2lit*Bookings.Qty FROM Rate,Bookings WHERE Bookings.Book_id=IN_book_id)); 
-- end
END IF;
END

1 个答案:

答案 0 :(得分:0)

The mySql showing "8 errors found" at the bottom

The parsing error thrown

即使脚本显示错误,该脚本也成功应用。以数字开头的列号后退标记解决了该问题。刷新后,它已从_SYNTAX_ERROR更改为其实际名称。