在Oracle中,可以使用DBA_SCHEDULER_JOBS视图来查找当前正在运行的作业(job),并使用DBMS_SCHEDULER.STOP_JOB过程来停止它们
sql
SELECT JOB_NAME, STATE FROM DBA_SCHEDULER_JOBS WHERE STATE = 'RUNNING';
SELECT * FROM DBA_SCHEDULER_JOBS WHERE STATE = 'RUNNING' and owner='ATLAS';
上面的SQL查询会列出所有当前状态为RUNNING的作业,即正在运行的作业。
要停止这些作业,可以编写一个PL/SQL块来遍历这些作业并停止它们
sql
DECLARE
CURSOR running_jobs IS
SELECT JOB_NAME
FROM DBA_SCHEDULER_JOBS
WHERE STATE = 'RUNNING' and owner='ATLAS';
v_job_name VARCHAR2(200);
BEGIN
OPEN running_jobs;
LOOP
FETCH running_jobs INTO v_job_name;
EXIT WHEN running_jobs%NOTFOUND;
DBMS_SCHEDULER.STOP_JOB(v_job_name);
END LOOP;
CLOSE running_jobs;
END;
/
或者kill会话
sql
select 'alter system kill session '''||sid||','||serial#||''';' from gv$session where machine like'WIN-%' and inst_id=1
union all
select 'alter system kill session '''||sid||','||serial#||''';'from gv$session where machine ='frdb1' and schemaname ='ATLAS'
vi kill_s.sql
@kill_s.sql