Wednesday, May 26, 2010

Select all data when parameter is null

Sometimes we need to display data based on report parameter and sometimes when user does not input anything, the default action is to display all data.
There are three ways we can use on WHERE clause on SQL:
where column_name = nvl(:parameter, column_name)
or
where column_name like nvl(:parameter, '%')
or
where (column_name = :parameter or :parameter is null)

Friday, May 21, 2010

Identify long running session and kill it

Sometimes you can find an Oracle database session that has been running for very long time. You can find it with this query:
select s.username,s.sid,s.serial#,s.last_call_et/60 mins_running,q.sql_text from v$session s 
join v$sqltext_with_newlines q
on s
.sql_address = q.address
where status='ACTIVE'
and type <>'BACKGROUND'
and last_call_et> 60
order
by sid,serial#,q.piece
Then you can kill it with (change sid and serial# using result from query above):
ALTER SYSTEM KILL SESSION 'sid,serial#';

Wednesday, May 19, 2010

Delete old archivelog

To delete old archivelog, use rman and login.
use this command:
change archivelog until time 'sysdate-x' delete;

Change x with number of days (1,2,3...).