oracle for循环执行sql

  • Post author:
  • Post category:其他


declare 
  num number := 1;
	sql_tem Varchar2(100);
begin
  while num <= 10
  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 COUNT(1) FROM USERS %'    ) 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;
 



版权声明:本文为qq_22802643原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。