Search code examples
sqlsqlplusprivileges

Limit user in sql plus to a single record in a table


I have one employee table...this table has 5 columns (empname, empgsm, empsal, empaddr, empdep) ...it has 10 records. I've created 10 users equivalent to the empnames column in the table. When a user logs in with his empname aka username & password, he will be able to see only his record from the table.

e.g. Smith is an employee, a user called smith was created. when this user is in session, and types "Select * from Employee_table" he only gets the record that belongs to him, where empname is smith.

How do I do this using privileges?


Solution

  • My sugestion is to create view on the table where include where condition based on curent user name some thing like this:

    select * from employee t
    where sys_context('USERENV','SESSION_USER') = t.empname`enter code here