我有两张桌子:
`deal` (`value`, `when`, `AccountTo`, `AccountFrom`, `Name`)
`account` (`AccountNumber`, `Value`)
我设置了一个程序:
CREATE PROCEDURE transfer
(IN Value_IN float,
IN When_IN int(4),
IN AccountTo_IN varchar(26),
IN AccountFrom_IN varchar(26),
IN Name_IN varchar(30))
NOT DETERMINISTIC
SQL SECURITY DEFINER
COMMENT ''
INSERT INTO deal
(value, when, AccountTo, AccountFrom, Name)
VALUES (Value_IN, When_IN, AccountTo_IN, AccountFrom_IN, Name_IN);
UPDATE account SET Value=(Value+Value_IN) WHERE AccountNumber=AccountTo_IN;
UPDATE account SET Value=(Value-Value_IN) WHERE AccountNumber=AccountFrom_IN;
数据被放入“交易”但“帐户”表未更新
编辑:
感谢您的回答。它是这样工作的:
CREATE DEFINER=`root`@`localhost` PROCEDURE `transfer`(
Value_IN FLOAT,
When_IN DATE,
AccountTo_IN VARCHAR(26),
AccountFrom_IN VARCHAR(26),
Name_IN VARCHAR(30))
BEGIN
INSERT INTO deal
(value, when, AccountTo, AccountFrom, Name)
VALUES (value_IN, When_IN, AccountTo_IN, AccountFrom_IN, Name_IN);
UPDATE account SET Value = Value+Value_IN) WHERE AccountNumber = AccountTo_IN;
UPDATE account SET Value = Value-Value_IN) WHERE AccountNumber = AccountFrom_IN;
END;