How is the grant command used in Oracle?
In Oracle database, the GRANT command is used to give specific permissions and privileges to users or roles. The basic syntax is as follows:
GRANT privilege [, privilege ...]
ON [object]
TO {user | role | PUBLIC}
[WITH GRANT OPTION];
- Privilege: Refers to the specific permission that can be granted, which can include system permissions, roles, or object permissions.
- Object: specifies the object for which permissions are being granted, such as a table, view, or stored procedure in the database.
- user: Specify the user you want to grant permission to.
- role: specify the role to grant permissions.
- PUBLIC: Granting permission to all users.
- WITH GRANT OPTION allows the user who has been granted permission to pass on that permission to other users or roles.
For example, the following command grants the user “test_user” SELECT and INSERT permissions on the table “employees”:
GRANT SELECT, INSERT ON employees TO test_user;
This command grants the role “admin_role” full permissions to the table “employees” and allows the role to delegate these permissions to other users.
GRANT ALL ON employees TO admin_role WITH GRANT OPTION;
Note: The GRANT command must be executed by a user with the appropriate permissions.