SHARE
TWEET

Untitled

a guest Nov 20th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE TRIGGER trg_update_stok
  2. AFTER INSERT OR DELETE OR UPDATE ON pesanan
  3. FOR EACH ROW
  4. DECLARE
  5. tmp_stok NUMERIC;
  6. BEGIN  
  7.    IF INSERTING THEN
  8.     SELECT stok INTO tmp_stok FROM produk WHERE id_produk = :new.id_produk;
  9.     IF (:new.jumlah <= tmp_stok) THEN
  10.        UPDATE produk SET stok = (tmp_stok - :new.jumlah) WHERE id_produk = :new.id_produk;
  11.     ELSE
  12.        RAISE_APPLICATION_ERROR(-20000, 'Stok tidak mencukupi');
  13.     END IF;
  14.    ELSIF UPDATING THEN
  15.     SELECT stok INTO tmp_stok FROM produk WHERE id_produk = :new.id_produk;
  16.     IF (:new.jumlah <= tmp_stok + :old.jumlah) THEN
  17.         UPDATE produk SET stok = ((tmp_stok + :old.jumlah) - :new.jumlah) WHERE id_produk = :old.id_produk;
  18.     ELSE
  19.         RAISE_APPLICATION_ERROR(-20000, 'Stok tidak mencukupi');
  20.     END IF;
  21.    ELSIF DELETING THEN
  22.       UPDATE produk SET stok = (stok + :old.jumlah) WHERE id_produk = :old.id_produk;
  23.    END IF;
  24. END;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top