oracle 9I升级到11g用户的迁移

公司要升级9I的数据库到11g,这下把我累晕了。那么多的用户,那么多的表空间,还有那么多的数据要全部弄到11g。

      实在没有办法用toad一条一条的复杂创建用户的语句,所以就写了一个创建用户的脚本,用他来代替一下。呵呵有点简单,不过有些问题没有完成处理好,比如原库有的用户expired,locked等,我就只出来了同时为'EXPIRED & LOCKED'的这种,其他的你们可以根据需求自己改。

-- Created on 2012/9/18 by XIONGLANG619 
declare 
  -- Local variables here
  v_sql varchar2(2000);
begin
  -- Test statements here
  for cc in (select t.username,t.password,t.default_tablespace,t.temporary_tablespace,profile from dba_users t where t.account_status='OPEN') loop
    /*if cc.account_status='EXPIRED & LOCKED' then
        v_sql:='create user '||cc.username||' identified by '||'"'||cc.password||'"'||' default tablespace '||cc.default_tablespace
           ||' temporary tablespace '||cc.temporary_tablespace||' profile '||cc.profile||' account lock'||';';
     else
        v_sql:='create user '||cc.username||' identified by '||'"'||cc.password||'"'||' default tablespace '||cc.default_tablespace
           ||' temporary tablespace '||cc.temporary_tablespace||' profile '||cc.profile||';';
     end if;*/
     --dbms_output.put_line(v_sql);
     --授予角色权限
     
     for yy in (select r.granted_role,r.grantee from dba_role_privs r where r.grantee=cc.username) loop
        v_sql:='grant '||yy.granted_role||' to '||yy.grantee||';';
        dbms_output.put_line(v_sql);
     end loop;
     
     --授予系统权限
     
     for xx in (select s.privilege,s.grantee from dba_sys_privs s where s.grantee=cc.username )loop
        v_sql:='grant '||xx.privilege||' to '||xx.grantee||';';
        dbms_output.put_line(v_sql);
     end loop;
     
     --授予对象权限
     /*
     for zz in (select t.privilege,t.owner,t.table_name,t.grantee from dba_tab_privs t where t.grantee=cc.username)loop
        v_sql:='grant '||zz.privilege|| ' on '||zz.owner||'.'||zz.table_name||' to '||zz.grantee||';';
        dbms_output.put_line(v_sql);
     end loop;
     */
     
     --授予表空间量的访问
     for dd in (select ts.user_name,ts.ts_name,ts.maxblocks,ts.blocksize from sys.ku$_tsquota_view ts where ts.user_name=cc.username) loop
        if dd.maxblocks<>-1 then
           v_sql:='alter user '||dd.user_name||' quota '||dd.maxblocks*dd.blocksize||' on '||dd.ts_name||';';
        else
           v_sql:='alter user '||dd.user_name||' quota unlimited on '||dd.ts_name||';';
        end if;
        dbms_output.put_line(v_sql);
     end loop;
  end loop;
end;


       执行顺序:必须先创建角色;然后根据脚本生成创建用户,授予系统权限,授予角色权限,授予表空间的访问权限的命令;其次导入数据;最后呢才根据脚本生成授予对象的权限。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值