How to Create a User With Full Privileges in PL/SQL?
Last Updated :
23 Jul, 2025
In database administration, the ability to manage user privileges is very important. As a database administrator, we may find ourselves in the position of creating users with full privileges and granting them the authority to manage and manipulate the database.
In this article, we will learn about CREATE USERS and give them GRANT or Privileges to access information using various methods and examples too.
How to Create a User with Full Privileges?
As a database administrator, one of our key responsibilities is to create users with full privileges often referred to as superusers or administrators. Below are three methods that can help us to CREATE USERS and give FULL Privileges to access information in PL/SQL are as follows:
- Using the CREATE USER Statement
- Using the GRANT Statement
- Using the DBMS_SQL Package
1. Using CREATE USER Statement
The CREATE USER
statement is a fundamental command for database administrators allowing them to create new users and grant them specific privileges within the database. It requires specifying the username and password for the new user.
Syntax for Create a New User:
CREATE USER username IDENTIFIED BY password;
Here we can substitute “username” for the desired name, whereas “password” stands for a secure access key.
Example: Let’s say we wanted to create a user called "Anya" with the password "pass123."
CREATE USER anya IDENTIFIED BY pass123;
Output:
Create a New UserExplanation: Our User has been created.
Let's Granting Privileges to the Anya
In PL/SQL, GRANT statement plays an important role in giving away administrative or DBA rights. Depending upon specific needs, GRANT statement is used for different allocation of privileges. This command grants all database administration rights across entire databases upon this specific user by dint of his DBA role.
Syntax for Grant Privileges:
GRANT DBA TO username;
Example: For instance, anya receives full database administration privileges through the DBA role.
GRANT DBA TO anya;
Output:
Granting PrivilegesExplanation: As we can see in the above image that privileges grant to the Anya. See in the below image to get visual representation of grant privileges Anya

2. Using GRANT statement
The GRANT statement is an adaptable tool that can be used to allocate privileges granting fine-grained control over a user’s access to various database resources. The syntax for granting DBA role with admin option is:
GRANT DBA TO username WITH ADMIN OPTION;
This does not only give “anya” the DBA role but also allows her to pass it on to other users.
GRANT DBA TO anya WITH ADMIN OPTION;
Output:
GRANT DBA TO anya WITH ADMIN OPTIONOn top of that, specific system privileges like creating tables and sessions may be granted one by one:
GRANT CREATE TABLE, CREATE SESSION TO username;
In this way, a more differentiated assignment of privileges can be made depending on individual requirements.
GRANT CREATE TABLE, CREATE SESSION TO anya;
Output:
OutputExplanation: In the above query we grants the user "anya" the permissions to create tables and to establish a session in the database. This allows "anya" to create new tables and to connect to the database for executing queries and accessing data.
3. Using the DBMS_SQL Package
For a more programmatic approach to user privilege management in PL/SQL, the DBMS_SQL Package is used. This package allows for creating and running SQL statements within PL/SQL that are dynamic.
DECLARE
sql_cursor INTEGER;
sql_stmt VARCHAR2(100);
BEGIN
sql_stmt := 'GRANT DBA TO anya';
sql_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(sql_cursor, sql_stmt, DBMS_SQL.NATIVE);
DBMS_SQL.CLOSE_CURSOR(sql_cursor);
END;
Output:
Using the DBMS_SQL PackageExplanation: In this dynamic example, the GRANT command assigns the DBA role to user “Anya”. The statement is parsed using the DBMS_SQL.PARSE procedure and then closed cursor.
Conclusion
Overall, themanaging user privileges in database administration is important. In this article we have explored three methods in PL/SQL for creating users with full privileges. The CREATE USER
statement allows for user creation, while the GRANT
statement offers to get control over privileges. Additionally, the DBMS_SQL
package provides a programmatic approach for dynamic SQL execution. Mastering these methods is essential for ensuring users have the necessary access to manage and manipulate the database effectively.
Similar Reads
How to Create a New User With Full Privileges in PostgreSQL? PostgreSQL provides a way to give a user full privileges to do anything with the database. The database objects like schema, table, function, and so on. The 'GRANT' command is used in PostgreSQL to provide a user with any specific privileges or to override the role of the user. In this article, we a
6 min read
How to Create User With Grant Privileges in MariaDB In database management, effective user management and privilege assignment are important for secure and efficient operations. MariaDB, a popular open-source relational database management system, offers robust features for managing users and their access rights. In this article, we will understand h
4 min read
How to Grant Admin Privileges to a User in Linux Linux is an operating system that is open source operating system. There are many distros available in Linux distribution like Ubuntu, Kali Linux, Arch Linux, and Red Hat Linux. In this article, we will understand how to give admin privileges to non-admin users in the Ubuntu Operating system. Introd
5 min read
How to Create Login, User and Grant Permissions in SQL Server Managing logins, users and permissions in SQL Server is a critical aspect of database security and administration. This process ensures that only authorized individuals have access to the database and can perform necessary operations. In this article, we will learn how to create and manage logins, a
5 min read
Oracle DataBase - Grant Privileges to a User in SQL Command Line Oracle Database is a robust and widely utilized relational database management system (RDBMS) recognized for its scalability, advanced features and performance optimization. Its architecture supports complex queries and large datasets also making it a popular choice for organizations of all sizes. I
4 min read
How to List All Users in PostgreSQL If we need to access all the users in our PostgreSQL database, we are in the right place. Whether we are a database administrator or a developer, having a clear method to list all users is essential for managing access and permissions. This article will guide us through a simple and effective way to
4 min read