Skip to Main Content

SQL Developer Data Modeler

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Generate DDL for DB users roles & privileges

886954Oct 21 2011 — edited Oct 21 2011
Dear All:

We are using Oracle 10.2.0.4, and planned to migrate on 11.2.0.2.
We want to generate ddl to create database users, grant the roles and privileges.

I am able to generate the DDL to create the users (with below PL/SQL code), but DDL to grant roles and privileges is required.
set serveroutput on SIZE 10000000
spool D:\DB_Upgrade\Pre_Upgrade_Scripts\create_users.sql
declare
  user_script CLOB;
  cursor cur_user IS
    select username
      from dba_users
     where account_status = 'OPEN'
       and username not in ('SYS',
                            'SYSTEM',
                            'SYSMAN',
                            'DBSNMP',
                            'SQLTXPLAIN',
                            'TRCANLZR',
                            'MGMT_VIEW');

BEGIN
  dbms_output.put_line('set serveroutput on SIZE 10000000;');
  dbms_output.put_line('spool create_users.log;');
  for rec_user in cur_user LOOP
  
    select dbms_metadata.get_ddl('USER', rec_user.username) || ';'
      into user_script
      from dual;
    dbms_output.put_line(user_script);
  end loop;
  dbms_output.put_line('spool off;');
end;
/
Regards,

Hassan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2011
Added on Oct 21 2011
3 comments
641 views