title: About how to create in Oracle Express - SQL. A trigger to update a column
body: <p>I have a <code>product</code> table and a <code>sales</code> table. Inside the <code>product</code> I have <code>(product_id, p_desc, qty_stock)</code> and in the <code>sales</code> table I have <code>(sale_id, producto_id, sale_p_qty)</code> where <code>sale_p_qty</code> is the quantity that a customer buys from a certain product. </p>
  
  <p>The question would be how can I make a trigger to update the <code>qty_stock</code> column value in the <code>product</code> table (this value would be the stock)? I can not do it. I can do a trigger that decrements, but only one value at a time. The correct one would be to get the <code>sale_p_qty</code> of table <code>sales</code> and decrement in <code>qty_stock</code> but I can not do that. Could you please give me a hand?</p>
  
  <p>My attempt stopped at this (I did not do a procedure, I do not know if you need to in this case):</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER trg_stock_ai AFTER INSERT OR UPDATE ON sale
  FOR EACH ROW
  declare
      new_stock NUMBER (4);
      --SELECT sale_p_qty INTO new_stock FROM sale
      --SET new_stock = (SELECT sale_p_qty FROM sale);
  BEGIN
      SELECT sale_p_qty INTO new_stock FROM sale;
      UPDATE product
      SET qty_stock = qty_stock - new_stock
      WHERE product.product_id =: NEW.product_id;
  END;
  </code></pre>