Question

I've managed to created an audit table in Oracle that audits records when they have been updated, deleted or inserted on the employees table. I have also made it so it only audits records when changes are made out of office hours (9am - 5pm).

IF you want to see the code for this please let me know, but i just wondered would it be possible to only audit records based on job role aswell. In the employee table there is a job role column such as this.

 Job_role
 Director
Security Guard II
Administration Manager
Warehouse Assistant I

I would only want it to audit changes made by for example a security guard or a warehouse assistant as these jobs roles should not really be interacting with the employee database.

Any help appreciated.

Thank you

Était-ce utile?

La solution

What you need to do is store the user's job description in a session variable.

To do this you declare a namespace using the CREATE CONTEXT command. Docs here.

Then you have an AFTER-LOGON database trigger which queries the USERS table and stores the Job Description in the namespace using DBMS_SESSION.set_context(). Docs here.

Finally, when it comes to the auditing command you read the stored value with SYS_CONTEXT() and make the appropriate decision:

if sys_context('AUDIT_INFO', 'JOB_DESCR') = 'Warehouse Assistant I'   
then
    call_your_audit_proc(.....);
end if;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top