简体   繁体   中英

MySQL Stored Procedure Case Statement Syntax Error - Contd 2

One Syntax Error in the following code. The response of the mysql was

Error 1064: 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 ''300ml','500ml','1lit','2lit') VALUES(m_cust_id,IN_book_id,(SELECT Rate.Can*Book' at line 24 SQL Statement

The following is the procedure.

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

MySql在底部显示“找到8个错误”

引发分析错误

The script applied successfully even if it showed error. The Back Tick to column names starting with digits solved the issue. Upon Refreshing, it got changed from _SYNTAX_ERROR to its actual name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM