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?

    Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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: