我将我的公司数据库从MySQL迁移到另一家不知道托管公司使用MariaDB的托管公司,在尝试使用我的IN参数创建我的存储过程时,MariaDB将该参数视为一个列。请参阅下面的存储过程代码,并显示错误:
CREATE PROCEDURE ADD_WITHDRAWAL_A(IN withdrawalcode_p VARCHAR(25), IN id_p VARCHAR(8), IN amount_p VARCHAR(12), IN datewithdrawn_p VARCHAR(35), IN approved_p VARCHAR(8))
START TRANSACTION;
INSERT INTO Withdrawals(WithdrawalCode, IDD, Amount, DateWithdrawn, Approved)
VALUES (withdrawalcode_p, id_p, amount_p, datewithdrawn_p, approved_p);
UPDATE account SET AccountBalance = AccountBalance - amount_p WHERE IDD = id_p LIMIT 1;
COMMIT;
***** AFTER RUNNING THE ABOVE CODE, MARIADB GAVE THIS ERROR :
Error
SQL query:
INSERT INTO WithdrawalRequest( WithdrawalCode, IDD, Amount, DateWithdrawn, Approved )
VALUES (withdrawalcode_p, id_p, amount_p, datewithdrawn_p, approved_p);
MySQL said: Documentation
#1054 - Unknown column 'withdrawalcode_p' in 'field list'
列名是WithdrawalCode,而不是' withdrawcode_p',' withdrawcode_p'是传递给存储过程的参数,但服务器将其视为字段名称。我与托管公司进行了交谈,他们说他们的数据库是MariaDB而不是MySQL。这个代码在MySQL服务器上运行。
我将非常感谢此处提供的有用帮助。
答案 0 :(得分:1)
您忘记设置非默认分隔符并将过程正文包装到BEGIN
/ END
中,这是必要的,因为它有多个语句。
在您的情况下,使用正文START TRANSACTION
创建的过程会发生什么,其余的被认为是一组普通的陈述。相反,尝试
DELIMITER $$
CREATE PROCEDURE ADD_WITHDRAWAL_A(IN withdrawalcode_p VARCHAR(25), IN id_p VARCHAR(8), IN amount_p VARCHAR(12), IN datewithdrawn_p VARCHAR(35), IN approved_p VARCHAR(8))
BEGIN
START TRANSACTION;
INSERT INTO Withdrawals(WithdrawalCode, IDD, Amount, DateWithdrawn, Approved)
VALUES (withdrawalcode_p, id_p, amount_p, datewithdrawn_p, approved_p);
UPDATE account SET AccountBalance = AccountBalance - amount_p WHERE IDD = id_p LIMIT 1;
COMMIT;
END $$
DELIMITER ;