--1.Khoá các user dang open (tru SYS%, %GGATE) luu lai thành scrip lock_user.sql
select 'alter user ' || username || ' account lock;' from DBA_USERS
where account_status='OPEN'
--2. Kill các session INACTIVE, ACTIVE theo ung instance
SELECT /*username*/ 'kill -9 ' || SPID A ,a.INST_ID,A.SID,A.SQL_ID, a.USERNAME, a.STATUS,A.SCHEMANAME,a.OSUSER,A.MACHINE,A.PROGRAM,A.TYPE,A.LOGON_TIME
FROM gv$session a, gv$process b
WHERE b.ADDR = a.paddr
AND a.inst_id=b.inst_id
AND B.inst_id = 1
AND A.username not in ('SYS','SYSTEM','SYSMAN','GGATE','GOLDENGATE')
and type='USER';
--3. Cap nhat table, package core: Subs, cust
--4. Buil lai các Package invalid:
select 'ALTER '||OBJECT_TYPE||' '||OWNER||'.'||OBJECT_NAME||' COMPILE;' from dba_objects
where object_type in ('PROCEDURE','FUNCTION','TRIGGER','PACKAGE','VIEW') and status like 'INVALID' and OWNER like 'TEST_OWNER'
UNION ALL
select 'ALTER PACKAGE '||OWNER||'.'||OBJECT_NAME||' COMPILE BODY;' from dba_objects
where object_type in ('PACKAGE BODY') and status like 'INVALID' and OWNER like 'TEST_OWNER'
--5. Check lai tu TOAD xem da valid het chua (Mục Used By)
--6. Unlock user: script
--7.Check UD