首页 > 数据库 >Oracle migrate the users into another DB instance

Oracle migrate the users into another DB instance

时间:2023-05-20 13:55:44浏览次数:38  
标签:username DBMS users migrate into user PUT OUTPUT LINE

---------------------------------------------
-- ###############OnSource###################
---------------------------------------------

create or replace procedure pr_user_ddl as

cursor get_username is
select username
from dba_users where username like '%SYS%';



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

begin

for l_user in get_username loop

DBMS_OUTPUT.PUT_LINE('-----------------------');
DBMS_OUTPUT.PUT_LINE('select (case');
DBMS_OUTPUT.PUT_LINE(' when ((select count(*)');
DBMS_OUTPUT.PUT_LINE(' from dba_users');
DBMS_OUTPUT.PUT_LINE(' where username = '''||l_user.username||''') > 0)');
DBMS_OUTPUT.PUT_LINE(' then dbms_metadata.get_ddl (''USER'', '''||l_user.username||''')');
DBMS_OUTPUT.PUT_LINE(' else to_clob ('' -- Note: User not found!'')');
DBMS_OUTPUT.PUT_LINE(' end ) "--Extracted_DDL" from dual');
DBMS_OUTPUT.PUT_LINE('UNION ALL');

DBMS_OUTPUT.PUT_LINE('-----------------------');
DBMS_OUTPUT.PUT_LINE('select (case');
DBMS_OUTPUT.PUT_LINE(' when ((select count(*)');
DBMS_OUTPUT.PUT_LINE(' from dba_ts_quotas');
DBMS_OUTPUT.PUT_LINE(' where username = '''||l_user.username||''') > 0)');
DBMS_OUTPUT.PUT_LINE(' then dbms_metadata.get_granted_ddl (''TABLESPACE_QUOTA'', '''||l_user.username||''')');
DBMS_OUTPUT.PUT_LINE(' else to_clob ('' -- Note: No TS Quotas found!'')');
DBMS_OUTPUT.PUT_LINE(' end ) from dual');
DBMS_OUTPUT.PUT_LINE('UNION ALL');

DBMS_OUTPUT.PUT_LINE('-----------------------');
DBMS_OUTPUT.PUT_LINE('select (case');
DBMS_OUTPUT.PUT_LINE(' when ((select count(*)');
DBMS_OUTPUT.PUT_LINE(' from dba_role_privs');
DBMS_OUTPUT.PUT_LINE(' where grantee = '''||l_user.username||''') > 0)');
DBMS_OUTPUT.PUT_LINE(' then dbms_metadata.get_granted_ddl (''ROLE_GRANT'', '''||l_user.username||''')');
DBMS_OUTPUT.PUT_LINE(' else to_clob ('' -- Note: No granted roles found!'')');
DBMS_OUTPUT.PUT_LINE(' end ) from dual');
DBMS_OUTPUT.PUT_LINE('UNION ALL');

DBMS_OUTPUT.PUT_LINE('-----------------------');
DBMS_OUTPUT.PUT_LINE('select (case');
DBMS_OUTPUT.PUT_LINE(' when ((select count(*)');
DBMS_OUTPUT.PUT_LINE(' from dba_role_privs');
DBMS_OUTPUT.PUT_LINE(' where grantee = '''||l_user.username||''') > 0)');
DBMS_OUTPUT.PUT_LINE(' then dbms_metadata.get_granted_ddl (''DEFAULT_ROLE'', '''||l_user.username||''')');
DBMS_OUTPUT.PUT_LINE(' else to_clob ('' -- Note: No System Privileges found!'')');
DBMS_OUTPUT.PUT_LINE(' end ) from dual');
DBMS_OUTPUT.PUT_LINE('UNION ALL');

DBMS_OUTPUT.PUT_LINE('-----------------------');
DBMS_OUTPUT.PUT_LINE('select (case');
DBMS_OUTPUT.PUT_LINE(' when ((select count(*)');
DBMS_OUTPUT.PUT_LINE(' from dba_sys_privs');
DBMS_OUTPUT.PUT_LINE(' where grantee = '''||l_user.username||''') > 0)');
DBMS_OUTPUT.PUT_LINE(' then dbms_metadata.get_granted_ddl (''SYSTEM_GRANT'', '''||l_user.username||''')');
DBMS_OUTPUT.PUT_LINE(' else to_clob ('' -- Note: No System Privileges found!'')');
DBMS_OUTPUT.PUT_LINE(' end ) from dual');
DBMS_OUTPUT.PUT_LINE('UNION ALL');

DBMS_OUTPUT.PUT_LINE('-----------------------');
DBMS_OUTPUT.PUT_LINE('select (case');
DBMS_OUTPUT.PUT_LINE(' when ((select count(*)');
DBMS_OUTPUT.PUT_LINE(' from dba_tab_privs');
DBMS_OUTPUT.PUT_LINE(' where grantee = '''||l_user.username||''') > 0)');
DBMS_OUTPUT.PUT_LINE(' then dbms_metadata.get_granted_ddl (''OBJECT_GRANT'', '''||l_user.username||''')');
DBMS_OUTPUT.PUT_LINE(' else to_clob ('' -- Note: No Object Privileges found!'')');
DBMS_OUTPUT.PUT_LINE(' end ) from dual');
DBMS_OUTPUT.PUT_LINE('/');
DBMS_OUTPUT.PUT_LINE('----------------------------------------------------------------------');

end loop;

end;
/



set pages 50000
set long 20000 longchunksize 20000 pagesize 0 linesize 1000 feedback off verify off trimspool on
column ddl format a1000
set serveroutput on size unlimited
spool /tmp/create_user_ddl_to_be_ran.sql
exec pr_user_ddl
spool off


--------------------------------------------
-- ###############OnTarget##################
---------------------------------------------
spool /tmp/user_created_history.log
set long 1000000000
set pages 50000
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
@/tmp/create_user_ddl_to_be_ran.sql
spool off
---------------------------------------------
-- ###########################################
---------------------------------------------

  

标签:username,DBMS,users,migrate,into,user,PUT,OUTPUT,LINE
From: https://www.cnblogs.com/Jeona/p/17417127.html

相关文章

  • How to migrate mailboxes from O365 to O365?
    Office365isapowerfulsuiteofapplicationsthatoffersawiderangeoffeaturestohelpbusinessesrunefficiently.However,asbusinessesgrow,theyoftenneedtomergeoracquireothercompanies,leadingtotenant-to-tenantmigration.Thisarticlew......
  • oracle中的merge into用法解析
    1.如果存在更新,不存在插入MERGEINTOmerge_targettargetUSING(SELECTB.name,B.age,B.target_idFROMmerge_sourceB)sourceON(target.id=source.target_id)WHENMATCHEDTHENUPDATESETtarget.name=source.name,target.age=source.ageWHENNOTMATCHE......
  • 华硕 PRIME H610M-A D4 i5-12490F 1060电脑 Hackintosh 黑苹果efi引导文件
    原文来源于黑果魏叔官网,转载需注明出处。(下载请直接百度黑果魏叔)硬件型号驱动情况主板华硕PRIMEH610M-AD4(LPCController/eSPIControllerH610芯片组)处理器12thGenIntelCorei5-12490F六核已驱动内存 16GB(酷兽DDR43200MHz8GBx2)已驱动硬盘三星SSD860EVO250G......
  • 开发 Diffusers 库的道德行为指南
    我们正在努力让我们每次发布的库更加负责!我们很荣幸宣布我们发布了道德守则,并将作为一部分其放入 Diffusers库的说明文档。由于扩散模型在现实世界上的实际应用例子会对社会造成潜在的负面影响,该守则旨在引导对于社区做出贡献的Diffusers库维护者进行技术决策。我们希望对......
  • Lenovo m93 mini 电脑 Hackintosh 黑苹果efi引导文件
    原文来源于黑果魏叔官网,转载需注明出处。(下载请直接百度黑果魏叔)硬件型号驱动情况主板Lenovom93mini处理器[email protected](35w)4-core/4-thread已驱动内存8GB(2x4)DDR31600MHz已驱动硬盘2.5"SSDSamsung860EVO500GB已驱动显卡IntelHDGraphics4000已驱动声......
  • ERROR: pip's dependency resolver does not currently take into account all the pa
    报错原因:ERROR:pip'sdependencyresolverdoesnotcurrentlytakeintoaccountallthepackagesthatareinstalled.Thisbehaviouristhesourceofthefollowingdependencyconflicts.scipy1.7.3requiresnumpy<1.23.0,>=1.16.5,butyouhavenumpy......
  • Dell Inspirion 5547电脑 Hackintosh 黑苹果efi引导文件
    原文来源于黑果魏叔官网,转载需注明出处。(下载请直接百度黑果魏叔)硬件型号驱动情况主板DellInspirion5547处理器Inteli5-4210U已驱动内存16GB(KLEVVDDR42400MHz/金士顿DDR42400MHz)已驱动硬盘CT1000MX500SSD1(1TB/固态硬盘)已驱动显卡IntelHDGraphics4400已驱......
  • 关于Linux系统-sshd服务-AllowUsers与AllowGroups-选项的安全加固配置
    在一些Linux系统-sshd服务,的主配置文件,/etc/ssh/sshd_config 我们可能会看到配置有AllowUsers与AllowGroups的安全加固选项,关于两个选项的说明如下:从选项名称上就可以知道这两个是选项,是属于白名单选项的,在安全中,如果能使用白名单模式,肯定是更安全的这里我们先说一下 AllowU......
  • API网关:开源Apinto网关-上游服务篇(二)
    功能介绍服务发现是一种分布式系统中的关键技术,它能够帮助应用程序动态地发现和访问依赖的服务实例,解决了服务实例分布在不同节点上的问题。通过服务发现,应用程序可以快速找到需要调用的服务实例的位置和元数据信息,并实现负载均衡和故障恢复等功能,从而提高分布式系统的可用性和性能......
  • API网关:开源Apinto网关-上游服务篇(二)
    功能介绍服务发现是一种分布式系统中的关键技术,它能够帮助应用程序动态地发现和访问依赖的服务实例,解决了服务实例分布在不同节点上的问题。通过服务发现,应用程序可以快速找到需要调用的服务实例的位置和元数据信息,并实现负载均衡和故障恢复等功能,从而提高分布式系统的可用性和......