Tuesday, September 30, 2014

Allow Admin users to Insert/Update/Delete on certain table



Allow Admin users to Insert/Update/Delete on certain table
How to create a trigger in oracle which will restrict insertion and update queries on a table based on a condition

CREATE OR REPLACE TRIGGER SIEBEL.BLOCK_NON_ADMIN_ACCESS
BEFORE DELETE OR INSERT OR UPDATE
ON SIEBEL.CX_ERROR_LOG
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
begin
    IF sys_context('USERENV','SESSION_USER') NOT IN ('SADMIN', 'EIMUSER') THEN
        RAISE_APPLICATION_ERROR(-20000, 'You are not allowed to update table CX_ERROR_LOG. Please contact Application Support.');
    END IF;
END;