问题
I wanted to create a trigger which when a new order is inserted in the ORDERS table the trigger updates the status level of a customer in the CUSTOMER table, depending on how many orders they have made. If a customer has 0 orders his status level is 'new' else if he has more than 1 he is a 'standard' customer.
The trigger below works if I add the customer_no in manually:
create or replace TRIGGER STATUS_CHECK
AFTER INSERT ON ORDERS
DECLARE
n INT;
BEGIN
SELECT COUNT(ORDER_NO)
INTO n
FROM ORDERS
INNER JOIN CUSTOMER
ON CUSTOMER.CUSTOMER_NO = ORDERS.CUSTOMER_CUSTOMER_NO
WHERE CUSTOMER.CUSTOMER_NO = '01';
IF(n > 1) THEN
UPDATE CUSTOMER
SET CUSTOMER.STATUS_LEVEL = 'STANDARD'
WHERE CUSTOMER.CUSTOMER_NO = '01';
END IF;
END;
来源:https://stackoverflow.com/questions/34246317/oracle-sql-status-check-trigger