我有一个带有数量变量的批量库存表。我还有一个名为采购订单的数量变量。当用户下达采购订单时,我希望在批量库存表中删除他们在采购订单表中插入的数量。我使用名为Apex的SQL oracle软件来做这件事。我相信我正在努力学习SQL语法:
Error: ORA-01747: invalid user.table.column, table.column, or column specification
这是我的代码
UPDATE Bulk_stock
SET Bulk_stock.bulk_quantity = Bulk_stock.bulk_quantity - purchase_order.order_quantity,
WHERE EXISTS
(SELECT 1
FROM purchase_order
WHERE Bulk_stock.stock_id = purchase_order.stock_id);
答案 0 :(得分:0)
purchase_order.order_quantity
后有一个额外的逗号。除了在您的更新声明中,您引用purchase_order.order_quantity
这是不正确的,因为更新发生在Bulk_stock
表上。
你能试试这个:
UPDATE Bulk_stock
SET Bulk_stock.bulk_quantity = Bulk_stock.bulk_quantity - nvl( SELECT purchase_order.order_quantity
FROM purchase_order
WHERE purchase_order.stock_id = Bulk_stock.stock_id WHERE ROWNUM=1), 0) WHERE EXISTS
(SELECT 1
FROM purchase_order
WHERE Bulk_stock.stock_id = purchase_order.stock_id);