sqlmon.sql
上传用户:rjj0351
上传日期:2007-01-07
资源大小:9k
文件大小:3k
源码类别:

Oracle数据库

开发平台:

SQL

  1. set feedback off
  2. set verify off
  3. set serveroutput on
  4. declare
  5. t_number1 number :=0;
  6. t_lines   number :=&1;
  7. t_sid     number :=&2;
  8. cursor c_usrsqls is
  9.  select sqt.sorts
  10.        ,sqt.disk_reads
  11.        ,sqt.buffer_gets
  12.        ,sqt.rows_processed
  13.        ,sqt.executions
  14.        ,sqt.first_load_time
  15.        ,sqt.sharable_mem
  16.        ,sqt.persistent_mem
  17.        ,sqt.runtime_mem
  18.        ,sqt.users_opening
  19.        ,sqt.users_executing
  20.    from v$sqlarea               sqt
  21.        ,v$session               ses
  22.   where ses.sql_address = sqt.address
  23.     and ses.sql_hash_value = sqt.hash_value
  24.     and ses.sid = t_sid;
  25. cursor c_usrsqlt is
  26.  select sqt.sql_text
  27.        ,sqt.piece
  28.    from v$sqltext_with_newlines sqt
  29.        ,v$session               ses
  30.   where ses.sql_address = sqt.address
  31.     and ses.sql_hash_value = sqt.hash_value
  32.     and ses.sid = t_sid
  33.   order by 2;
  34. begin
  35.  dbms_output.enable(100000);
  36.  for r_usrsqls in c_usrsqls 
  37.  loop
  38.    dbms_output.put_line('first_load_time='||
  39.                          ltrim(r_usrsqls.first_load_time)
  40.                        );
  41.    dbms_output.put_line('sorts='||
  42.                          ltrim(to_char(r_usrsqls.sorts,'990'))||
  43.                         ',disk_reads='||
  44.                          ltrim(to_char(r_usrsqls.disk_reads,'999999990'))||
  45.                         ',buffer_gets='||
  46.                          ltrim(to_char(r_usrsqls.buffer_gets,'999999990'))||
  47.                         ',rows_processed='||
  48.                          ltrim(to_char(r_usrsqls.rows_processed,'999999990'))
  49.                        );
  50.    dbms_output.put_line('executions='||
  51.                          ltrim(to_char(r_usrsqls.executions,'9999990'))||
  52.                         ',users_opening='||
  53.                          ltrim(to_char(r_usrsqls.users_opening,'990'))||
  54.                         ',users_executing='||
  55.                          ltrim(to_char(r_usrsqls.users_executing,'990'))
  56.                        );
  57.    dbms_output.put_line('sharable_mem='||
  58.                          ltrim(to_char(r_usrsqls.sharable_mem,'99990'))||
  59.                         ',persistent_mem='||
  60.                          ltrim(to_char(r_usrsqls.persistent_mem,'99990'))||
  61.                         ',runtime_mem='||
  62.                          ltrim(to_char(r_usrsqls.runtime_mem,'99990'))
  63.                        );
  64.  end loop;
  65.  dbms_output.put_line('--------------------------------------------------------------------------');
  66.  t_number1 := 0;
  67.  for r_usrsqlt in c_usrsqlt 
  68.  loop
  69.    dbms_output.put_line(rpad(ltrim(r_usrsqlt.sql_text),64));
  70.    t_number1 := t_number1 + 1;
  71.    exit when t_number1 = t_lines;
  72.  end loop;
  73. end;
  74. /