在Oracle中,可以用kill session来终止一个会话进程,其基本语法结构为:
alter system kill session 'sid,serial' ;
被kill掉的session,状态会被标记为killed
SQL> select saddr,sid,serial#,paddr,username,status from v$session where username is not null;
SADDR SID SERIAL# PADDR USERNAME STATUS
---------------- ---------- ---------- ---------------- ------------------------------ --------
0000000237399AC0 34 315 000000023A2B8B10 SCOTT INACTIVE
00000002373C5350 66 412 00000002372F35A0 SCOTT ACTIVE
000000023A40BA00 161 1064 000000023A2BABF0 SCOTT INACTIVE
0000000237447D00 162 1294 000000023A2B6A30 SCOTT INACTIVE
000000023A43A100 191 954 00000002372F14C0 SCOTT INACTIVE
000000023A465990 223 214 000000023A2B7AA0 SCOTT INACTIVE
SQL> alter system kill session '223,214';
System altered
SQL> select saddr,sid,serial#,paddr,username,status from v$session where username is not null;
SADDR SID SERIAL# PADDR USERNAME STATUS
---------------- ---------- ---------- ---------------- ------------------------------ --------
0000000237399AC0 34 315 000000023A2B8B10 SCOTT INACTIVE
00000002373C5350 66 412 00000002372F35A0 SCOTT ACTIVE
000000023A40BA00 161 1064 000000023A2BABF0 SCOTT INACTIVE
0000000237447D00 162 1294 000000023A2B6A30 SCOTT INACTIVE
000000023A43A100 191 954 00000002372F14C0 SCOTT INACTIVE
000000023A465990 223 214 00000002373343C8 SCOTT KILLED
6 rows selected