我有两个表,需要创建一个触发器,当使用相应的Order_id创建执行时,执行数量被添加到Order表中的Quantity_filled时,这需要作为一个或多个执行的累积量可以添加到订单中,订单表中的版本增加1。
已经管理了几个日期触发器,但却在努力解决这个问题。
订购表
Key Field Type Description
--------------------------------------------------------
P ORDER_ID Number(6) Order identifier.
CREATE_DATETIME Date Date of order.
F INSTRUMENT_ID Number(6) Instrument identifier.
AMEND_DATETIME Date Date of last order amendment or deletion.
QUANTITY Number(12) QUANTITY
VERSION Number(2) Order version.
QUANTITY_FILLED Number(12) Quantity Filled
执行表
Key Field Type Description
--------------------------------------------------------
P EXECUTION_ID Number(6) Unique execution identifier.
BUY_SELL Char(1) Buy/Sell indicator:
‘B’ – buy;
‘S’ – sell;
EXEC_DATETIME Date Date of execution.
F INSTRUMENT_ID Number(6) Instrument identifier.
EXECUTION_PRICE Number(12) Price in dealt currency.
QUANTITY Number(12) Execution quantity.
F ORDER_ID Number(6) Order identifier.
已尝试过此次数量更新但收到错误。我可以访问整个互联网,但直到明天我回到Uni才能看到它们是什么。
创建触发器ExecQuantityUpdate 在INSERT ON执行后,BEGIN更新ORDERS设置QUANTITY_FILLED = NEW.QUANTITY,其中ORDER.QUANTITY_FILLED = NEW.QUANTITY END;
试过这个,但仍然出现错误
Create Trigger ExecQuantityUpdate
AFTER INSERT ON Execution
FOR EACH ROW
BEGIN
UPDATE orders
SET quantity_filled = quantity_filled + NEW.quantity
WHERE order_id = NEW.order_id
AND id = NEW.execution_id;
END
答案 0 :(得分:1)
它必须是:NEW
,而不仅仅是NEW