2016-07-28 78 views
0

我是第一個使用phpmyadmin的計時器。我不知道在我的存儲過程中,我正在使用我的代碼。我不知道如何在phpmyadmin中創建存儲過程。在phpmyadmin中存儲過程

這是我的代碼:

DELIMITER $$ 
CREATE PROCEDURE sp_1_service_card_report(IN service_card_no INT) 
BEGIN 
    DECLARE error_1 INT; 

    SELECT COUNT(service_card.customer_id) 
    INTO error_1 
    FROM service_card 
    WHERE service_card.id = 27; 

    DECLARE error_2 INT; 

    SELECT COUNT(service_card.serial_no_id) 
    INTO error_2 
    FROM service_card 
    WHERE service_card.id = 27; 

    IF error_1 > 0 AND error_2 > 0 THEN 
    SELECT 
     service_card.id as yes from service_card where service_card.id=27; 
    ELSE 
     SELECT service_card.customer_id as no from service_card.id=27; 
    END IF ; 

END $$ 
DELIMITER ; 

這是我的錯誤:

MySQL said: Documentation

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DECLARE error_2 INT;

SELECT COUNT(service_card.serial_no_id)
INTO ' at line 11

你們能幫助我嗎?我花了我的1小時搜索答案也在這裏在stackoverflow。

謝謝。

+0

我不知道爲什麼你長了這個錯誤,但沒有ü嘗試以移動線就在error_1聲明行之下? –

+0

嘗試將第二個DECLARE移到第一個之後。 –

+0

我只是把eror_2放在最上面。由於逗號(;),我剛剛得到了紅色的X點「我只是不明白我做錯了什麼。 –

回答

0

DECLARE語句必須放在第一,你必須在查詢select錯字在你的程序的結束:

DELIMITER $$ 
CREATE PROCEDURE sp_1_service_card_report(IN service_card_no INT) 
BEGIN 
    DECLARE error_1 INT; 
    DECLARE error_2 INT; 

    SELECT COUNT(service_card.customer_id) 
    INTO error_1 
    FROM service_card 
    WHERE service_card.id = 27; 


    SELECT COUNT(service_card.serial_no_id) 
    INTO error_2 
    FROM service_card 
    WHERE service_card.id = 27; 

    IF error_1 > 0 AND error_2 > 0 THEN 
    SELECT 
     service_card.id as yes from service_card where service_card.id=27; 
    ELSE 
     SELECT service_card.customer_id as no from service_card where service_card.id=27; 
    END IF ; 

END $$ 
DELIMITER ;