ORACLE SQL Status check trigger

倖福魔咒の 提交于 2020-01-07 05:32:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!