当前所在位置:珠峰网资料 >> 计算机 >> Oracle认证 >> 正文
通过TABLEFUNCTION获得ORACLE权限(三)
发布时间:2010/10/26 9:50:57 来源:www.xue.net 编辑:城市总裁吧

    Function ListSysPrivs(ObjOwner varchar2 default null) return PrivsList pipelined is

    c cur;

    v_sql varchar2(2000);

    begin

    v_sql:=‘select grantee,privilege from dba_sys_privs where grantee in (’||nvl(FromStrToStr(ObjOwner),‘Grantee’)||‘)

    order by 1‘;

    –dbms_output.put_line(v_sql);

    open c for v_sql;

    loop

    fetch c into v_owner,v_privs;

    exit when c%notfound;

    pipe row(upper(rpad(v_owner,30,‘ ’)||‘ : ’||v_privs));

    end loop;

    close c;

    return ;

    end;

    Function ListRolePrivs(ObjOwner varchar2 default null) return PrivsList pipelined is

    c cur;

    v_sql varchar2(2000);

    begin

    v_sql:=‘select grantee,Granted_Role from dba_role_privs where grantee in (’||nvl(FromStrToStr(ObjOwner),‘Grantee’)||‘)

    order by 1‘;

    –dbms_output.put_line(v_sql);

    open c for v_sql;

    loop

    fetch c into v_owner,v_privs;

    exit when c%notfound;

    pipe row(upper(rpad(v_owner,30,‘ ’)||‘ : ’||v_privs));

    end loop;

    close c;

    return ;

    end;

    Function ListRoleSysPrivs(ObjOwner varchar2 default null) return PrivsList pipelined is

    c cur;

    v_sql varchar2(2000);

    begin

    v_sql:=‘select s1.grantee,s1.granted_role,s2.privilege from dba_role_privs s1,role_sys_privs s2 where s1.granted_role=s2.role and s1.grantee in (’||nvl(FromStrToStr(ObjOwner),‘s1.Grantee’)||‘)

    order by 1‘;

    –dbms_output.put_line(v_sql);

    open c for v_sql;

    loop

    fetch c into v_owner,v_role,v_privs;

    exit when c%notfound;

    pipe row(upper(rpad(v_owner,30,‘ ’)||‘ : ’||rpad(v_role,30,‘ ’)||‘ : ’||v_privs));

    end loop;

    close c;

    return ;

    end;

    Function ListRoleTabPrivs(ObjOwner varchar2 default null) return PrivsList pipelined is

    c cur;

    v_sql varchar2(2000);

    begin

    v_sql:=‘select s1.grantee,s1.granted_role,s2.owner,s2.table_name,s2.privilege from dba_role_privs s1,role_tab_privs s2 where s1.granted_role=s2.role and s1.grantee in (’||nvl(FromStrToStr(ObjOwner),‘s1.Grantee’)||‘)

    order by 1‘;

    –dbms_output.put_line(v_sql);

    open c for v_sql;

    loop

    fetch c into v_grantee,v_role,v_owner,v_name,v_privs;

    exit when c%notfound;

    pipe row(upper(rpad(v_grantee,30,‘ ’)||rpad(v_role,30,‘ ’)||‘ : ’||‘ : ’||rpad(v_owner,30,‘ ’)||‘ : ’||rpad(v_name,30,‘ ’)||‘ : ’||v_privs));

    end loop;

    close c;

    return ;

    end;

    Procedure RevokeTabPrivs(ObjOwner varchar2 , ObjName varchar2 default null, Privs varchar2 default null,

    Grantee varchar2 default null) is

    c cur;

    v_sql varchar2(2000);

    begin

    v_sql:=‘select grantee,owner,table_name,privilege from dba_tab_privs where owner in (’||nvl(FromStrToStr(ObjOwner),‘owner’)||‘) and table_name in (’||nvl(FromStrToStr(ObjName),‘Table_name’)||‘) and privilege in (’||nvl(FromStrToStr(Privs),‘Privilege’)||‘) and grantee in (’||nvl(FromStrToStr(Grantee),‘Grantee’)||‘) order by 1,2 ’;

    open c for v_sql;

    loop

    fetch c into v_grantee,v_owner,v_name,v_privs;

    exit when c%notfound;

    begin

    dbms_output.enable;

    dbms_output.put_line(upper(‘revoke ’||v_privs||‘ on ’||v_owner||‘.'||v_name||’ from ‘||v_grantee||’;'));

    exception

    when others then null;

    end;

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved