Reputation: 3
I'm creating a database with oracle and php for an assignment and i have to show the use of roles. i created a new role called employee and assigned it to a new user called employee1
CREATE ROLE read_only;
GRANT create session TO read_only;
GRANT select ON workson TO read_only;
GRANT select ON employee TO read_only;
GRANT select ON project TO read_only;
GRANT select ON department TO read_only;
CREATE ROLE employee;
GRANT read_only TO employee;
GRANT update ON employee TO employee;
GRANT insert ON workson TO employee;
Create user employee1 identified by qwerty1;
GRANT employee TO employee1;
Why does using any selects when connected as employee1 say there is no such table. select * from employee says there is no table. Did i form my roles wrong or something?
Upvotes: 0
Views: 288
Reputation: 231651
Your grants appear to be fine. Assuming that the employee1
user does not own the employee
table, you would need to qualify the table name in your SELECT
with the owner of the table. For example, if we're talking about the employee
table that is owned by the hr
user, you'd need to
SELECT *
FROM hr.employee;
If you don't want to have to qualify your table names, you have a couple of options. First, you can create synonyms. You can create a private synonym in the employee1
schema that applies only to the employee1
user
CREATE SYNONYM employee
FOR hr.employee;
or you can create a public synonym that applies to all users
CREATE PUBLIC SYNONYM employee
FOR hr.employee;
The second option would be to set your current_schema
after connecting.
ALTER SESSION SET current_schema=hr;
If you have an appropriate synonym in place or if you've set the current_schema
, you don't have to prefix the table name with the owner of the table.
Upvotes: 2