Friday, July 11, 2008

SCRIPT:To Check All Active Sql

To check all active sql:
set feedback off
set serveroutput on size 9999


col username for a25
col sql_text format a60 word_wrapped
begin
for x in
(select username '('sid','serial#') ospid = ' process
' program = ' program username,
to_char(LOGON_TIME,' Day HH24:MI') logon_time,
to_char(sysdate,' Day HH24:MI') current_time, sql_address,
sql_hash_value

from v$session
where status = 'ACTIVE'
and rawtohex(sql_address) <> '00'
and username is not null ) loop
for y in (select sql_text from v$sqlarea
where address = x.sql_address )

loop
if ( y.sql_text not like '%listener.get_cmd%'

and y.sql_text not like '%RAWTOHEX(SQL_ADDRESS)%' )
then
dbms_output.put_line( '--------------------' );
dbms_output.put_line( x.username );
dbms_output.put_line( x.logon_time ' ' x.current_time ' SQL#=' x.sql_hash_value);
dbms_output.put_line( substr( y.sql_text, 1, 250 ) );
end if;

end loop;
end loop;
end;


Note: Please check the select statement for v$session view in begin section of pl/sql block if in case its not executing and provide pipe characters to get exact results.

No comments: