首页 > 解决方案 > MySQL 说:#1064 - 你的 SQL 语法有错误;在存储过程中

问题描述

我正在尝试在 phpmyadmin 中创建一个存储过程。例如,我在 PHP MyAdmin 中执行此操作

 UPDATE financeplusacct SET bal = bal - 5000 WHERE accNum = 00343297587;
UPDATE financeplusacct SET bal = bal + 5000 WHERE accNum = 00343995977

它可以毫无顾虑地发布,然后我尝试将其设为存储过程,以便我的 Javascript REST api 可以轻松调用它,看起来像这样

UPDATE financeplusacct SET bal = bal - amount WHERE accNum = accNum1;
UPDATE financeplusacct SET bal = bal + amount WHERE accNum = accNum2;

我把它当作一个错误

One or more errors have occurred while processing your request:
The following query has failed: "CREATE DEFINER=`root`@`localhost` PROCEDURE `ExecDebitCredit`(IN `accNum1` VARCHAR(150), IN `accNum2` VARCHAR(150), IN `amount` DECIMAL(18,2)) NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER UPDATE financeplusacct SET bal = bal - amount WHERE accNum = accNum1; UPDATE financeplusacct SET bal = bal + amount WHERE accNum = accNum2;"

MySQL said: #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 'UPDATE financeplusacct SET bal = bal + amount WHERE accNum = accNum2' at line 2

请问有什么我没有得到正确的吗?

标签: mysqlsqlstored-procedures

解决方案


推荐阅读