Creating a trigger with a case statement

后端 未结 2 787
长情又很酷
长情又很酷 2021-01-13 11:59

I have these two tables:

USERS(username, role_id)
COMMISSION_RATES(username, commission_rate)

users.username is the primary ke

相关标签:
2条回答
  • 2021-01-13 12:42

    WHEN condition must be in the definition part, not in the body. They can only by used for row trigger.

    create or replace
    TRIGGER SETCOMISSIONRATE 
    AFTER INSERT ON USERS 
    FOR EACH ROW
    WHEN (NEW.role_id = 2)
    BEGIN
        INSERT INTO COMISSION_RATE
        (username,
        comission_rate)
        VALUES (
        :NEW.username,
        0)
    
    END;
    
    0 讨论(0)
  • 2021-01-13 12:56

    It should go like this:

    CREATE OR REPLACE TRIGGER SETCOMISSIONRATE 
    AFTER INSERT ON USERS FOR EACH ROW
    WHEN (new.role_id = 2)
    BEGIN
        INSERT INTO COMISSION_RATE (username, comission_rate)
        VALUES (:new.username, 0);
    END;
    
    0 讨论(0)
提交回复
热议问题