1. First take all the information using dbm_metadata.
set head off
set pages 0
set long 9999999
select dbms_metadata.get_ddl('USER', username) || '/' usercreate
from dba_users;
ALTER USER "SYS" IDENTIFIED BY VALUES 'S:1CCB2C8B206B3D3BA9164214F3262051E4C0
D076179455300F8674EDBC85;E100B964899CDDDF'
TEMPORARY TABLESPACE "TEMP"
/
ALTER USER "SYSTEM" IDENTIFIED BY VALUES 'S:DC73635359324A39D3636017D54F482E7
F3D7CC34D0426EA3C9628FFD120;970BAA5B81930A40'
TEMPORARY TABLESPACE "TEMP"
/
CREATE USER "SOUMYA" IDENTIFIED BY VALUES 'S:3F6E037E8574BC8FB1F0CF44651E0DE9
7C8765DC0924224F19F7F43D583B;6673D7515E467AA4'
DEFAULT TABLESPACE "USERS"
TEMPORARY TABLESPACE "TEMP"
PASSWORD EXPIRE
/
To get all their roles and grants:-
SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT','SYS') FROM DUAL;
SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','SYS') FROM DUAL;
SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT','SYS') FROM DUAL;
To script it in a single command:-
spool '/u01/app/dbusersinfo.sql'
select dbms_metadata.get_ddl( 'USER', 'HR' ) from dual
UNION ALL
select dbms_metadata.get_granted_ddl( 'SYSTEM_GRANT', 'HR' ) from dual
UNION ALL
select dbms_metadata.get_granted_ddl( 'OBJECT_GRANT', 'HR' ) from dual
UNION ALL
select dbms_metadata.get_granted_ddl( 'ROLE_GRANT', 'HR' ) from dual;
spool off
GRANT SELECT ON "HR"."D01" TO "SCOTT"
GRANT SELECT ON "HR"."FILOM" TO "SCOTT"
GRANT SELECT ON "HR"."HD01" TO "SCOTT"
GRANT SELECT ON "HR"."HSPRF" TO "SCOTT"
GRANT SELECT ON "HR"."SPRF" TO "SCOTT"
GRANT SELECT ON "HR"."HFILOM" TO "SCOTT"
GRANT "CONNECT" TO "SCOTT"
GRANT "RESOURCE" TO "SCOTT"
Now run the above output into database server where you want to migrate the users.
No comments:
Post a Comment