oracle断开用户所有连接


DECLARE
   u_sid  varchar2(50);
   u_serialnumber varchar2(50);
   u_name varchar2(50);
   CURSOR c1 IS select trim(s.sid),trim(s.serial#)
                              from v$session s,v$process p
                              where s.paddr = p.addr  and (s.username=u_name); 
BEGIN
   -- 替换用户名,必须大写
    u_name:=’TEST’;
   OPEN c1; 
   LOOP
      FETCH c1 INTO u_sid,u_serialnumber;
      EXIT WHEN c1%NOTFOUND;
      EXECUTE IMMEDIATE ’alter system kill session ’||’’’’||trim(u_sid)||’,’||trim(u_serialnumber)||’’’’;
   END LOOP;
END;


Whatever is worth doing is worth doing well.