zoukankan      html  css  js  c++  java
  • Oracle管理监控之测试环境清理用户脚本

    --PL/SQL块删除用户

    declare
      cursor cur_duser is
        select sid, serial# from v$session where username in ('T1');
      v_str string(200);
    begin
      for d_u in cur_duser loop
        v_str := 'alter system kill session ' || '''' || d_u.sid || ',' ||
                 d_u.serial# || '''';
        execute immediate v_str;
      end loop;
      v_str := 'drop user T1 cascade';
      execute immediate v_str;
    end;

    declare
      cur_duser sys_refcursor;
      v_sid     v$session.sid%type;
      v_serial# v$session.serial#%type;
      v_str     string(200);
      uname     string(20);
    begin
      uname := 't1';
      open cur_duser for
        select sid, serial# from v$session where username in (uname);
      loop
        fetch cur_duser
          into v_sid, v_serial#;
        exit when cur_duser%notfound;
        v_str := 'alter system kill session ' || '''' || v_sid || ',' ||
                 v_serial# || '''';
        execute immediate v_str;
      end loop;
      close cur_duser;
      v_str := 'drop user ' || uname || ' cascade';
      execute immediate v_str;
    end;

    --过程删除用户

    create or replace procedure drop_user(uname string) is
      cursor cur_duser is
        select sid, serial# from v$session where username in (uname);
      v_str string(200);
    begin
      for d_user in cur_duser loop
        v_str := 'alter system kill session ' || '''' || d_user.sid || ',' ||
                 d_user.serial# || '''';
        execute immediate v_str;
      end loop;
      dbms_lock.sleep(10);
      v_str := 'drop user ' || uname || ' cascade';
      execute immediate v_str;
    end;

  • 相关阅读:
    python课堂整理5---元组
    用python输出回文数
    python课堂整理4---列表的魔法
    python基础知识练习题一
    python课堂整理3---字符串魔法
    python课堂整理2
    python课堂整理1
    励志程序媛---从厂妹到Google年薪60W RMB程序员
    动态链接库--靠谱
    基于VS2019———C++生成自己的静态链接库————良心实战笔记
  • 原文地址:https://www.cnblogs.com/wcwen1990/p/6660446.html
Copyright © 2011-2022 走看看