简体   繁体   中英

Oracle SQL trigger after insert, update table with corresponding columns

This is my code for creating the trigger update table with corresponding columns

CREATE TRIGGER TR_trig after insert ON TR
FOR EACH ROW
 
  UPDATE IT 
  SET ODNUM = TR.ODNUM,
  SET INEM = TR.INEM, 
  SET QTS = TR.QTS,
  SET PR = TR.PR,
  WHERE IT.ORNUM = TR.ORDNUM

 

Apart from zillion stupid errors, such as

  • typos
    • "price" vs. "prince"
    • "received" vs. "recieved"
    • "ordern0" (with zero at the end) vs. "orderno"
  • superfluous set keywords
  • missing statement terminator
  • missing end

the rest is "OK"; I mean, trigger compiles.

SQL> CREATE OR REPLACE TRIGGER trans_trig AFTER
  2    INSERT ON transactions
  3    FOR EACH ROW
  4  BEGIN
  5    UPDATE orders
  6    SET orderno = :new.orderno,
  7        cno = :new.cno,
  8        sno = :new.sno,
  9        received = :new.received,
 10        shipped = NULL, --:new.SHIPPED,
 11        type = :new.type
 12    WHERE orderno = :new.orderno;
 13
 14    UPDATE items
 15    SET orderno = :new.orderno,
 16        itemno = :new.itemno,
 17        quantity = :new.quantity,
 18        prince = :new.prince
 19    WHERE items.orderno = :new.orderno;
 20
 21  END;
 22  /

Trigger created.

SQL>

I suggest you be more careful as majority of errors could have been avoided, only if you paid attention. Another part is easily fixed by following basic syntax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM