Truncate Table: How to truncate table in another schema

Truncate table is one of the easiest command. You can truncate table in your schema. If you have to truncate tables in another schema; you need to have 'DROP ANY TABLE' privileges. 

Why you need privilege to truncate table in another schema?
It depends on how we design a system. There are architecture where we maintain different components of organization in different schema but use one single schema to access it may be in reports.

Here, DBAs and organization security dont prefer to grant 'DROP ANY TABLE' privileges to any other schema.Tom Kyte have suggested to use stored procedure to acheive the result. I am not going any different way either.

Design:
1) Procedure 'truncate_tabname'  to truncate table in every schema.
2) Grant exeute on the procedure 'truncate_tabname' to main schema.
3) Create wrapper procedure on main schema that calls the procedure 'xx'

STEP1: Create procedure on each schema.Below is script for HR, Repeat for FIN, MANUFACT and SHIP.

create or replace
PROCEDURE hr.truncate_tabname(p_owner IN VARCHAR2
,p_tabname IN VARCHAR2) as
-- Description : Stored procedure to truncate tables.
-- This procedure is called by a wrapper procedure truncate_tab in ADMIN schema.
-- This is a workaround for not granting 'DROP ANY TABLE' privilege to ADMIN and truncate tables in other schemas.
-- Usage : exec truncate_tabname(,);
v_object varchar2(100);
begin
v_object:=p_owner||'.'||p_tabname;
EXECUTE IMMEDIATE 'TRUNCATE TABLE ' || v_object;
DBMS_OUTPUT.PUT_LINE(v_object||' have been truncated.');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(v_object||' - Table may not exist !!!');
END truncate_tabname;

===========================

STEP2: grant execute on hr.truncate_tabname to ADMIN;

===========================

STEP3: Wrapper Procedue


create or replace
PROCEDURE ADMIN.truncate_tab(p_owner IN VARCHAR2
,p_tabname IN VARCHAR2
,p_confirm IN BOOLEAN) as

-- Description : This procedure inturns calls truncate_tabname procedure in each schema. 
-- This is a workaround for not granting 'DROP ANY TABLE' privilege to ADMIN and truncate tables in other schemas.
-- Usage : exec truncate_tab(,,);
v_owner varchar2(30);
v_tabname varchar2(100);
v_flag boolean;
v_error varchar2(200);

begin
v_owner:=upper(p_owner);
v_tabname:=upper(p_tabname);
v_flag:=p_confirm;

IF v_flag THEN
CASE v_owner
WHEN 'HR' THEN
hr.truncate_tabname(v_owner,v_tabname);
WHEN 'FIN' THEN
fin.truncate_tabname(v_owner,v_tabname);
WHEN 'MANUFACT' THEN
manufact.truncate_tabname(v_owner,v_tabname);
WHEN 'SHIP' THEN
ship.truncate_tabname(v_owner,v_tabname);
ELSE
DBMS_OUTPUT.PUT_LINE('Sorry, You dont have privilege to truncate tables on '||v_owner);
END CASE;
ELSE DBMS_OUTPUT.PUT_LINE('Please confirm the truncate with FLAG to TRUE and Try again');
END IF;
EXCEPTION
WHEN OTHERS THEN
v_error := substr(sqlerrm, 1,200);
DBMS_OUTPUT.PUT_LINE('Error: '||v_error);
END truncate_tab;

===================

Thanks to my friend Alson for code review. 

Oracle Database Patch: 10.2.0.5

Initially 10.2.0.5 patchset was released with respect to Oracle Enterprise Manager (OEM). Oracle have released Oracle 10g 10.2.0.5 Database patch on Apr-29-2010. Oracle has released this database patch - 10.2.0.5 after 2 years of 10.2.0.4 patchset.

Below are the patch numbers:

5337014 Oracle Database Family: Patchset 10.2.0.3 PATCH SET FOR ORACLE DATABASE SERVER

6810189 Oracle Database Family: Patchset 10.2.0.4.0 PATCH SET FOR ORACLE DATABASE SERVER

8202632 Oracle Database Family: Patchset 10.2.0.5.0 PATCH SET FOR ORACLE DATABASE SERVER

Metalink note for manual upgrade to 10g R2 is 316889.1 (Complete Checklist for Manual Upgrades to 10gR2)

There is a confusion with what is meant by PSU. PatchSet Update (PSU) is a bunch of one off-patches and critical patch update (CPU). Always raise SR with oracle to confirm the upgrade process before doing it on Production.

Oracle: Duplicate Controlfile in ASM

Control file is one of the most critical components of Oracle Database. It is recommended to have multiple copies spread across different DISKGROUPS (in ASM) or different file system. If the control file is lost Database crashes.

Below are the steps for creating a duplicate control file in ASM with INIT file.

1. Shut down the database using Shutdown Immediate.

2. Edit the init.ora to include the second disk group.

Control_files=('+DISK1','+DISK2')

You can create directory within the DISKGROUP if needed. Below are the two ways to do that

a) Alter diskgroup DISK1 add directory '+DISK1/QA_DB/Control';

or

b)
ASMCMD> cd DISK1/QA_DB
ASMCMD> mkdir Control

3) Startup the database in NOMOUNT state.

4)
rman nocatalog
RMAN> Connect target
RMAN> Restore controlfile from '+DISK1/';

5) Mount the database followed by Open.

6) check the control file by
show parameter control.


Duplicate Control File in ASM with SPFILE

1) Modify the SPFile
Alter system set control_files='+Disk1/QA_DB/Control/current.xxx.yyyy','+DISK2' scope=spfile;

2) Start the instance in NOMOUNT state

3)
rman nocatalog
RMAN> connect target
RMAN> restore controlfile from '+Disk1/QA_DB/Control/current.xxx.yyyy';

4) Mount the database followed by brining to Open status.

5) Validate the controlfile
Select * from v$controlfile;

6) Edit the spfile and refer to the exact controlfile name

Alter system set control_files='+Disk1/QA_DB/Control/current.xxx.yyyy','+Disk2/QA_DB/Control/current.aaa.bbbbbbbb scope=spfile;


Thats it .. we are done.

We make JOY

Maryland: Another silent saturday, I was browsing through youtube.com randomly and saw many advertisements. Most of them were different, humor, some are outstanding. I love cars and checked videos of new models, new features, comparisons. I came across a three letter word 'JOY'. It is simply awesome. Its the BMW advt where the tag line is ' JOY Is BMW'.

Just wondering how creative the people in the world are. Some of the other attractive slogans are Apple's ' Think Different', Nokia's ' Connecting People', Nike's 'Just Do It', ' Think About It" - Hyundai.


@)!) - Catch This Out

Silver Spring, MD: December is one of the most exciting month for everyone. The planning starts long back the month is near. Family, friends, bf/gf, parents try to observe what their beloved is in need for and silently plan their gifts wrapped up.

I too was planning to get myself something.. a phone, a LCD, a trip to west coast.. outline was clear.. but it takes lot of calorie burn to make it happen.. lol !! I didnt get anything and Christmas day is here. Swingindale kallan gave me the first call.. I saw wishes flying from everywhere in facebook..

The most interesting fact about December is that, if you miss to celebrate Xmas as you expected.. exactly a week later you have another chance to feel special. Its Dec/31, I havent got anything yet.. wondering what is the special stuff I must get.. For 2009, I saw cries and pain everywhere starting with war, weak but recovering economy, ecology, job loss.. Hmm!!! Driving to church, tuning to Linkin Park - "Leave Out All The Rest" on my friend's car, realized my life itself is one of the best gift.

I asked for better prospect, I got inspired and encouraged to take it up and be a better surfer against high wave. I wanted a better job, I got the worst but was learning to survive..I didnt want to be alone, got lovable friends and family surrounding me.. Can't forget the smile and excitement of vava, when I surprised her for Thanksgiving.. lol worth lot more than Orlando trip. I wanted to learn technology, understood dimensions, facts, procedures, completed certification. I wanted a bigger mafia, made new facebook requests.. I asked for a power drive, I got a hybrid.. I missed all marriage functions of my schoolmates, but still I got an invitation.. They remembered me.

Sipping coffee, this wonderful morning.. just looking at the trees outside.. leaves shed with white snow held on its branches, I believe these stand still folks must be having the best of new hope.. we too are waiting to have leaves, fruits and have a picturesque fall.. A simple inspiration.

I THANK for air I breathe, bread I eat, every macro and micro entity. I have received everything in a better way than I could have imagined.. I didnt understand it until I look back.. Wish everyone an awesome @)!).