Why does this trigger fail? It says invalid identifier

1.1k Views Asked by At
CREATE MATERIALIZED VIEW ORDERS_MV
BUILD IMMEDIATE
REFRESH COMPLETE ON DEMAND AS
SELECT * FROM ORDERS;
---------------------------------------

CREATE OR REPLACE TRIGGER update_ship_receive
INSTEAD OF INSERT ON ORDERS_MV
FOR EACH ROW
BEGIN
  UPDATE ORDERS SET EXPECTED_SHIP_DATE = ORDER_DATE+5;
  UPDATE ORDERS SET EXPECTED_RECEIVE_DATE = SHIP_DATE+1 
WHERE SHIPPING_METHOD = '1 DAY';
  UPDATE ORDERS SET EXPECTED_RECEIVE_DATE = SHIP_DATE+2
 WHERE SHIPPING_METHOD = '2 DAY';
  UPDATE ORDERS SET EXPECTED_RECEIVE_DATE = SHIP_DATE+5 
WHERE SHIPPING_METHOD = 'GROUND';
END;
/
3

There are 3 best solutions below

1
On BEST ANSWER

Oracle can see your table structures. We can't. I'm betting Oracle sees the problem in your code.

It should point to the first line with the error. If not, select * from user_errors;

Maybe your ORDERS table doesn't have SHIP_DATE (since the first statement talks about EXPECTED_SHIP_DATE).

0
On

Not an Oracle guy, but shouldn't you use

:OLD.SHIP_DATE

or

:NEW.SHIP_DATE

and

:OLD.ORDER_DATE

or

:NEW.ORDER_DATE

refer: Oracle's trigger doc

0
On

I'm sorry,Why not create o BEFORE INSERT trigger on orders table? when create BEFORE INSERT trigger,if add a new row in orders table,Can use .NEW.EXPECTED_SHIP_DATE,.NEW.EXPECTED_RECEIVE_DATE update orders table. Don't create materialized view on orders