• nullnull使用PL/SQL获取创建用户的语句


    在写这篇文章之前,xxx已经写过了几篇关于改nullnull主题的文章,想要了解的朋友可以去翻一下之前的文章

        Create procedure:

    create or replace procedure get_case_sqls_for_ddls_ver1 as
      cursor get_username is
        select username from dba_users;
    
    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_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;
    /
        每日一道理
    航行者把树比作指引方向的路灯,劳动者把树比作遮风挡雨的雨伞,诗人把树比作笔下的精灵,而我却要把树比作教师,它就是为我们遮风挡雨的伞,指明方向的路灯,打开知识殿堂的金钥匙。

        The above proc when called with the foll. will give the SQLs for all users:

        

    set head off
    set pages 0
    set serveroutput on size unlimited
    spool /tmp/sqls_gathered_frm_trial_run_1.sql
    exec get_case_sqls_for_ddls_ver1 
    spool off

        These SQLs generated can in turn be run as follows to get the master-list of all the grants in the database:

        

    spool /tmp/grants_by_running_trial3_ver0.0.sql
    conn  / as sysdba
    set head off
    set long 1000000000
    set pages 0
    exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
    @/tmp/sqls_gathered_frm_trial_run_1.sql
    spool off

        

    文章结束给大家分享下程序员的一些笑话语录: 一条狗在街上闲逛,看见橱窗里一张告示:「招聘程序员。会编程,有团队精神,至少精通两种语言。均等机会。」
      那条狗就进去申请,但是被拒绝了。
      「我不能雇一条狗在公司里做事。」经理说。
      狗不服气,指着告示上「均等机会」几字抗议。
      经理没法,叹了口气,不屑地问道:「你会编程吗?」
      那条狗默默地走到电脑前,编了个程序,运作准确。
      「你有团队精神吗?」经理问。
      那条狗掉头看了看门外,一大群野狗在外面虎视耽耽。
      「我真的不能雇狗做这份工作。」经理气急败坏地说。
      「就算会编程、有团队精神,但是我需要的雇员至少要能精通两种语言。」
      那条狗抬头看着经理说:「喵-噢。」

  • 相关阅读:
    TCP详解——传输控制协议(总述)
    sublime text3使用插件SublimeTextTrans设置透明度
    vue学习1
    js事件绑定/监听
    如何成为顶级程序猿
    HTML5中meta属性
    windows安装SVN服务器并设置开机启动
    oracle安装登录sqlplus / as sysdba然后报错ERROR: ORA-01031 insufficient privileges
    移动端和PC端有什么区别
    div+css通用兼容性代码整理
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3087235.html
Copyright © 2020-2023  润新知