Monday, 4 July 2011

Oracle Database: Script to shutdown database

The following script can be used to shutdown the database by killing the session.

declare
cursor get_reg_users is
select sid, serial#
from v$session
where trunc(logon_time) > (select trunc(startup_time) from
v$instance);

sqltxt varchar2(200);
curr_sess exception;
pragma exception_init(curr_sess, -27);
begin
for urec in get_reg_users loop
sqltxt:='alter system kill session
'''||urec.sid||','||urec.serial#||'''';
execute immediate sqltxt;
end loop;
exception
when curr_sess then
null;
end;
/

No comments:

Post a Comment

Number of Visitors