我是使用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说:文档
1064 - 您的SQL语法出错;检查与您的MariaDB服务器版本对应的手册,以便在#DEC; DECLARE error_2 INT附近使用正确的语法;
SELECT COUNT(service_card.serial_no_id)
INTO'在第11行
你们能帮助我吗?我花了1个小时在stackoverflow上搜索答案。
感谢。
答案 0 :(得分: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 ;