Q

Create a new user

I want to create a new user with the same privileges as of one of our existing users. Could you please tell me the easiest way to do to accomplish this?
The easiest way to perform this operation is to query the Data Dictionary for the GRANT commands you'll need. First, create the new user. I'll assume the new user's name is NEW_USER and the old user's name is OLD_USER in my example.

CREATE USER new_user IDENTIFIED BY new_pass DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;

Now that the user has been created, you'll want to grant the appropriate roles, system privileges, and object privileges to the user. Run the following commands to generate the GRANT commands you'll need:

 -- Grant the roles to the new user.
SELECT 'GRANT '||granted_role||' TO new_user;'
FROM dba_role_privs WHERE grantee='OLD_USER'; --Grant the system privileges to the new user.
SELECT 'GRANT '||privilege||' TO new_user;'
FROM dba_sys_privs WHERE grantee='OLD_USER'; --Grant the object privilegs to the new user.
SELECT 'GRANT '||privilege||' ON '||owner||'.'||table_name||' TO new_user;'
FROM dba_tab_privs WHERE grantee='OLD_USER'; 

The SQL statements above will generate a series of GRANT commands. You can use these generated commands to grant the privileges to the new user.

This was first published in March 2005

Dig deeper on Oracle database design and architecture

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close