2

enter image description hereI have a bulk stock table with a quantity variable. I also have a quantity variable for a table called purchase order. When a user makes a purchase order I want the quantity they have inserted in the purchase order table to be deleted in the Bulk stock table. I am doing this using an SQL oracle software called Apex. I am struggling with SQL syntax i believe:

Error: ORA-01747: invalid user.table.column, table.column, or column specification

this is my code

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);
Tony Andrews
  • 129,880
  • 21
  • 220
  • 259
kuhle
  • 193
  • 2
  • 15
  • Could you pass in the value of the current purchase order id into the query as a bind variable? How does the rest of your code look like? – Mick Mnemonic Nov 16 '16 at 00:18
  • The insert is done automatically using that oracle apex form. This is the code i want to put as a process on the page AFTER the insert is done according to the image above. there is no extra code – kuhle Nov 16 '16 at 06:58
  • Are you allowed to create a `TRIGGER` in the database for encapsulating this business logic? – Mick Mnemonic Nov 16 '16 at 07:58
  • yes I am allowed. I tried creating a trigger but apex always cries about syntax. If you could help with a Begin-End; correct syntax for this kind of update. – kuhle Nov 16 '16 at 09:41
  • Did my answer work for you? – randominstanceOfLivingThing Nov 17 '16 at 21:43
  • This one worked for me http://stackoverflow.com/questions/40631582/how-to-trigger-an-update-on-a-table-row-value-using-a-row-value-from-another-tab/40632289#40632289 – kuhle Nov 19 '16 at 12:01

1 Answers1

0

There is an extra comma after purchase_order.order_quantity. Besides in your update statement you refer to purchase_order.order_quantity which is not correct since the update is happening on Bulk_stock table.

Can you try this one:

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);
randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72