- Create users and explain system privileges vs object privileges.
- Grant and revoke object privileges, including column-level and WITH GRANT OPTION.
- Access other users’ objects with owner prefixes, private and public synonyms.
- Create, grant, enable (SET ROLE) and drop roles, including password-protected roles.
- Use ALTER USER and common data dictionary views.
Users and Privileges
Every Oracle user needs a valid username and password. When a database is created Oracle creates SYS and SYSTEM, who can perform administrative operations (create/alter/drop users, roles, profiles, tablespaces). A new user is created by SYS or SYSTEM:
create user srikanth identified by oraclebook; connect srikanth/oraclebook -- ORA-01045: user SRIKANTH lacks CREATE SESSION privilege; logon denied grant connect, resource to srikanth; -- roles: log on, create and use objects
A privilege is a right to access an object or to execute a particular type of SQL command. A session starts at login and ends at logout; CONNECT moves from the current user to another user.
| System privilege | Object privilege | |
|---|---|---|
| Right to | Perform an operation in the system (CREATE SESSION, CREATE TABLE …) | Perform an operation on a specific object (table, view, sequence, procedure, function, package) |
| Usually granted | Through roles, by the DBA | By the object’s owner |
Object Privileges
The owner has complete access to his objects; other users have no access unless explicitly granted.
| Privilege | Allows | Object | Privileges available |
|---|---|---|---|
| ALTER | Change the definition | TABLE | SELECT, INSERT, DELETE, UPDATE, ALTER, INDEX, REFERENCES |
| DELETE / INSERT / UPDATE | Change rows | VIEW | SELECT, INSERT, UPDATE, DELETE |
| EXECUTE | Execute the object | SEQUENCE | SELECT, ALTER |
| INDEX | Create an index on it | PROCEDURE, FUNCTION, PACKAGE, OBJECT TYPE | EXECUTE |
| REFERENCES | Refer to it in a foreign key | ||
| SELECT | Select rows |
grant select on courses to praneeth; grant all on compbatches to praneeth; grant update(duration) on courses to praneeth; -- column-level (UPDATE/INSERT/REFERENCES) grant select on courses to praneeth with grant option; -- grantee may grant further -- as PRANEETH: select * from courses; -- ORA-00942: table or view does not exist select * from srikanth.courses; -- owner.tablename revoke select on courses from praneeth;
- ALL grants every applicable privilege; PUBLIC grants to every user.
- GRANT and REVOKE are DCL commands.
- CASCADE CONSTRAINTS drops foreign keys that were created using a REFERENCES privilege being revoked.
- Revoking is cascading: if A grants to B and B grants to C, revoking from B also removes it from C.
- Even with a privilege received from PRANEETH, ANURAG must still write
srikanth.coursesbecause SRIKANTH owns the table.
Synonyms
A synonym is an alias for a table or view that avoids writing the owner name. A private synonym is created in the account of the user who wants to use it; a public synonym is available to all users and needs the CREATE PUBLIC SYNONYM system privilege.
create synonym courses for srikanth.courses; -- in PRANEETH's account select * from courses; grant select on courses to public; -- by SRIKANTH create public synonym courses for srikanth.courses;
Roles
- A role is a collection of system and/or object privileges – granting privileges user by user and table by table is avoided.
- Roles are dynamic: privileges added to a role later are available to all its users.
- Creating a role needs the CREATE ROLE system privilege. Predefined roles include CONNECT, RESOURCE and DBA.
- A user can have many roles; only roles enabled (by default or with SET ROLE) give their privileges.
create role manager; -- or: identified by efficient grant select on courses to manager; grant select, update, insert, delete on batches to manager; grant manager to praneeth, anurag; set role manager; -- enable a granted role set role manager identified by efficient; -- password-protected role -- without password: ORA-01979: missing or invalid password for role 'MANAGER' drop role manager;
ALTER USER and Data Dictionary Views
alter user praneeth identified by tunu; -- change password alter user book default role all except manager; -- default roles
A user can change only his own password; other attributes are changed by the administrator. Data dictionary views (based on tables owned by SYS, created with the database) describe the database:
| View (synonym) | Contains |
|---|---|
| DICTIONARY (DICT) | Description of data dictionary views |
| USER_CATALOG (CAT) | Tables, views, synonyms and sequences owned by the user |
| USER_TABLES (TABS), USER_TAB_COLUMNS (COLS) | User’s tables / their columns |
| USER_OBJECTS (OBJ) | Objects owned by the user |
| USER_SEQUENCES (SEQ), USER_SYNONYMS (SYN), USER_INDEXES (IND) | Sequences, private synonyms, indexes |
| ALL_TAB_COLUMNS, ALL_OBJECTS | Columns / objects accessible to the user |
| USER_TAB_PRIVS, USER_COL_PRIVS | Table / column grants where the user is owner, grantor or grantee |
| USER_VIEWS, USER_ERRORS, USER_TRIGGERS, USER_TYPES, USER_CLUSTERS | View text, errors on stored objects, triggers, object types, clusters |
- System privileges control commands; object privileges control access to objects.
- WITH GRANT OPTION lets grantees re-grant; revoking cascades down the chain.
- Synonyms hide owner names; roles group privileges and must be enabled.
Chapter 13 Notes (PDF)
Question / Answer (15 questions)
Moderate-level questions based on the Chapter 13 notes (PDF). Click a question to see the answer.
MCQ Test : Check Your Understanding (5 questions)
Select an option and press Check Answer, or answer all questions and press Submit Test to see your score. Each answer comes with an explanation.
Bibliography/References
The chapter notes PDF is the course study material and is credited to its author below. The explanations, questions and MCQs on this page are original study aids written for this course from the topics covered in that PDF. The other works are cited for verification and further reading. Oracle, SQL*Plus and PL/SQL are trademarks of Oracle Corporation; other names belong to their respective owners.
- Srikanth, P. (n.d.). Oracle For Beginners (chapter notes – the PDF shown on each chapter page). Srikanth Technologies. http://www.srikanthtechnologies.com/
- Oracle Corporation. (n.d.). Oracle Database Security Guide, 19c. https://docs.oracle.com/en/database/oracle/oracle-database/19/dbseg/
- Oracle Corporation. (n.d.). Oracle Database SQL Language Reference, 19c. https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/
- Oracle Corporation. (n.d.). Oracle Database Reference (initialization parameters and data dictionary views), 19c. https://docs.oracle.com/en/database/oracle/oracle-database/19/refrn/
- Oracle Corporation. (n.d.). Oracle Database Administrator’s Guide, 19c. https://docs.oracle.com/en/database/oracle/oracle-database/19/admin/