1

I've got 2 tables:

`deal` (`value`, `when`, `AccountTo`, `AccountFrom`, `Name`)

`account` (`AccountNumber`, `Value`)

I set up a procedure:

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;

data is put into 'deal' but 'account' table is not updated

EDIT:

Thanks for answers. It works this way:

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;
4

1 に答える 1

1

INSERT の前と最後の UPDATE の後に BEGIN と END が必要になると思います。SQL/Server、MySQL、Sybase、Oracle など、多くのデータベースがこれに該当します。すべて BEGIN/END が必要です。

于 2015-10-12T21:48:59.167 に答える