oracle存储过程执行sql

--这里演示的是杀掉正在执行的指定sql
declare 
  num number := 1;
sql_tem Varchar2(100);
begin
  while num <= 5
  loop
     for v_rlt in ( SELECT b. SID, b.serial# FROM v$process A, v$session b, v$sqlarea c WHERE A .addr = b.paddr AND b.sql_hash_value = c.hash_value AND c.sql_text LIKE 'select * from tables where 1=1 '    ) loop

    sql_tem :='alter system kill session '' ' || v_rlt.SID  ||',' || v_rlt.SERIAL# || '''';
  dbms_output.put_line(sql_tem);
  EXECUTE IMMEDIATE sql_tem;
end loop;
  dbms_output.put_line('FOR循环已经结束!');
 num := num + 1;
  end loop;
end;

 

你可能感兴趣的:(oracle学习)