0

i wanted to copy all the rights,roles and mandant from one user to other. How to do this in plsql procedure or function. I am using oracle 12c database.

  • Does this answer your question? [How to clone user in Oracle](https://stackoverflow.com/questions/4468173/how-to-clone-user-in-oracle) – wolφi Jun 09 '20 at 09:49

1 Answers1

1

I use this script to generate user creation:

set long 1000000 pagesize 0 feedback off trimspool on verify off

begin
   dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'SQLTERMINATOR', true);
   dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'PRETTY', true);
end;
/

variable v_username VARCHAR2(30);

exec:v_username := upper('&1');

select dbms_metadata.get_ddl('USER', u.username)
from   dba_users u
where  u.username = :v_username
union all
select dbms_metadata.get_granted_ddl('TABLESPACE_QUOTA', tq.username)
from   dba_ts_quotas tq
where  tq.username = :v_username
and    rownum = 1
union all
select dbms_metadata.get_granted_ddl('ROLE_GRANT', rp.grantee)
from   dba_role_privs rp
where  rp.grantee = :v_username
and    rownum = 1
union all
select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', sp.grantee)
from   dba_sys_privs sp
where  sp.grantee = :v_username
union all
select dbms_metadata.get_granted_ddl('OBJECT_GRANT', tp.grantee)
from   dba_tab_privs tp
where  tp.grantee = :v_username
and    rownum = 1
union all
select dbms_metadata.get_granted_ddl('DEFAULT_ROLE', rp.grantee)
from   dba_role_privs rp
where  rp.grantee = :v_username
and    rp.default_role = 'YES'
and    rownum = 1
union all
select dbms_metadata.get_ddl('PROFILE', u.profile)
from   dba_users u
where  u.username = :v_username
and    u.profile <> 'DEFAULT'
/
sandman
  • 2,050
  • 9
  • 17
  • Hi,with the above script i can only fetch the grants given to the user :v_username. But i also wanted to give these grants to another user. basically copy these rights and grant to another user . – Sangathamilan Ravichandran Jun 10 '20 at 07:43
  • But once the script generates, it's a simple edit to replace the user name? – sandman Jun 11 '20 at 08:58