How to reduce the table size for any table while using truncate or delete statements. In oracle 8i it was truncating the storage space but in 10g it is not ....
I have given truncate statement in a procedure to drop the storage of a table used... when its record count exceeds 500. -
BEGIN
-
-
i:= 0;
-
-
FOR CC IN NLD LOOP
-
-
DELETE FROM CHN_BED5A_T4_FX ;
-
-
COMMIT;
-
-
DELETE FROM CHN_BED5B_T4_FX ;
-
-
COMMIT;
-
-
-
if i=500
-
then
-
EXECUTE IMMEDIATE('TRUNCATE table CHN_BED5A_T4_FX');
-
EXECUTE IMMEDIATE('TRUNCATE table CHN_BED5B_T4_FX');
-
i:= 0;
-
end if;
-
-
commit;
-
This is the part where i truncate..
Can anyone help me with truncating the storage space as well since i am not able to run my reports with this increasing table size.....
8 7718
Hi
Please try to put correct code enclosed with code tags when you ask for help.
Also do you want to reduce the size of datafile by releasing unused extents or you want to keep not more than 500 records in your tables? Please be specific.
Best Regds,
Bhushan
When ever you perform a TRUNCATE, the water mark is reset and the space occupied by the data in the table is released.
In case of delete, the data is deleted and moved to rollback segments, but the storage space is not released. The Water mark remains at same level.
For more detail, Check here
Hi ,
I am sorry for not pasting the complete code... here is the complete one... -
SET SERVEROUTPUT ON;
-
-
DECLARE
-
-
i number;
-
-
CURSOR NLD IS
-
SELECT A.ROWID AS TMP_ROWID,A.* FROM CHN_BILLREFDUMP3_T1_FX A WHERE A.STAT=0 AND A.STRM=1;
-
-
-
BEGIN
-
-
i:= 0;
-
-
FOR CC IN NLD LOOP
-
-
DELETE FROM CHN_BED3A_T4_FX ;
-
-
COMMIT;
-
-
DELETE FROM CHN_BED3B_T4_FX ;
-
-
COMMIT;
-
-
-
if i=500
-
then
-
EXECUTE IMMEDIATE('TRUNCATE table CHN_BED3A_T4_FX');
-
EXECUTE IMMEDIATE('TRUNCATE table CHN_BED3B_T4_FX');
-
i:= 0;
-
end if;
-
-
commit;
-
-
-
-
INSERT /*+ append */ INTO CHN_BED3A_T4_FX
-
SELECT /*+ ordered*/ 0,
-
A.JURISDICTION,A.RATE_DT,A.PRIMARY_UNITS,A.SECOND_UNITS,A.THIRD_UNITS,A.RATED_UNITS,
-
A.AMOUNT,B.MSG_ID,B.MSG_ID2,B.MSG_ID_SERV,B.SPLIT_ROW_NUM,B.ACCOUNT_NO,B.SUBSCR_NO,
-
B.SUBSCR_NO_RESETS,B.BILL_REF_NO AS INDEX_BILL_REF,B.BILL_REF_RESETS,B.BILLED_AMOUNT,
-
B.DISCOUNT,B.TRANS_DT,B.TYPE_ID_USG
-
FROM chn_cdr_data_CU3 A,chn_cdr_billed_CU3 B
-
WHERE a.CDR_DATA_PARTITION_KEY=b.CDR_DATA_PARTITION_KEY and
-
A.MSG_ID=B.MSG_ID AND A.MSG_ID2=B.MSG_ID2 AND A.MSG_ID_SERV=B.MSG_ID_SERV AND B.BILL_REF_NO=CC.INDEX_BILL_REF AND B.BILLED_AMOUNT>0 AND A.SPLIT_ROW_NUM=B.SPLIT_ROW_NUM;
-
-
COMMIT;
-
-
-
INSERT /*+ append */ INTO CHN_BED3B_T4_FX
-
SELECT /*+ ordered*/ MSG_ID,MSG_ID2,MSG_ID_SERV,BILL_REF_NO,COUNT(*) FROM chn_cdr_billed_CU3 WHERE BILLED_AMOUNT>0 AND
-
BILL_REF_NO=CC.INDEX_BILL_REF GROUP BY MSG_ID,MSG_ID2,MSG_ID_SERV,BILL_REF_NO;
-
-
COMMIT;
-
-
--DUMPING ALL THE CALLS WITH CALL SPLIT =1 EVEN IT IS AIRTIME OR PSTN
-
-
UPDATE CHN_BED3A_T4_FX A SET A.CNT=(SELECT NCNT FROM CHN_BED3B_T4_FX B WHERE B.INDEX_BILL_REF=A.INDEX_BILL_REF AND NCNT=1
-
AND A.MSG_ID=B.MSG_ID AND A.MSG_ID2=B.MSG_ID2 AND B.MSG_ID_SERV=A.MSG_ID_SERV) ;
-
-
COMMIT;
-
-
UPDATE CHN_BED3A_T4_FX A SET A.CNT=(SELECT NCNT FROM CHN_BED3B_T4_FX B WHERE B.INDEX_BILL_REF=A.INDEX_BILL_REF AND NCNT<>1
-
AND A.MSG_ID=B.MSG_ID AND A.MSG_ID2=B.MSG_ID2 AND B.MSG_ID_SERV=A.MSG_ID_SERV) WHERE
-
( CNT=0 OR CNT IS NULL) AND A.TYPE_ID_USG IN ( SELECT SUBTYPE_CODE FROM mis.CHTYPEMAST2 WHERE UPPER(ITEM_DESCRIPTION) LIKE '%AIR%'
-
OR UPPER(ITEM_DESCRIPTION) LIKE '%HIERARCHY%');
-
-
COMMIT;
-
-
DELETE FROM CHN_BED3A_T4_FX WHERE CNT IS NULL;
-
-
INSERT /*+ append */ INTO CHN_BILLBKUP3BDUMP_T3_FX
-
SELECT /*+ ordered*/ SUBSCR_NO,SUBSCR_NO_RESETS,TYPE_ID_USG,INDEX_BILL_REF,JURISDICTION,SUM(PRIMARY_UNITS) AS ACTDURN,
-
SUM(RATED_UNITS) AS CHARGED_UNITS,COUNT(*) AS CALLCOUNT ,SUM(SECOND_UNITS) AS ROAMDURN
-
FROM CHN_BED3A_T4_FX
-
GROUP BY SUBSCR_NO,SUBSCR_NO_RESETS,TYPE_ID_USG,INDEX_BILL_REF,JURISDICTION;
-
-
COMMIT;
-
-
INSERT /*+ append */ INTO CHN_BILLBKUP3_T2_FX (INDEX_BILL_REF,SUBSCR_NO,SUBSCR_NO_RESETS, SUBTYPE_CODE, RATE_TYPE, REVENUE_TYPE,
-
ITEM_CODE, ITEM_DESCRIPTION,AMOUNT,TAX,DISCOUNT, NET_AMT_IN_RUPEES)
-
SELECT /*+ ordered*/
-
BID.BILL_REF_NO,BID.SUBSCR_NO,SUBSCR_NO_RESETS,BID.SUBTYPE_CODE,BID.RATE_TYPE,
-
DECODE(BID.TYPE_CODE,2,'RC',3,'NRC',1,'PAY',7,'USG',4,'ADJ',6,'UC',TYPE_CODE,'OTH') AS REVENUE_TYPE,
-
BID.SUBTYPE_CODE AS ITEM_CODE,
-
DES.DESCRIPTION_TEXT AS ITEM_DESCRIPTION,
-
SUM(BID.AMOUNT) /100 AS AMOUNT ,
-
SUM(BID.TAX ) /100 AS TAX ,
-
SUM(BID.DISCOUNT) /100 AS DISCOUNT ,
-
SUM(BID.AMOUNT+BID.TAX+BID.DISCOUNT) /100 AS NET_AMT_IN_RUPEES
-
FROM chn_bill_invoice_detail_CU3 BID, chn_descriptions_CU3 DES
-
WHERE BID.BILL_REF_NO = CC.INDEX_BILL_REF
-
AND BID.subtype_code <>'-1050'
-
AND BID.DESCRIPTION_CODE = DES.DESCRIPTION_CODE(+)
-
AND BID.TYPE_CODE IN (2,3,4,7)
-
GROUP BY BID.BILL_REF_NO,BID.SUBSCR_NO,SUBSCR_NO_RESETS,DECODE(BID.TYPE_CODE,2,'RC',3,'NRC',1,'PAY',7,'USG',4,'ADJ',6,'UC',TYPE_CODE,'OTH'),
-
BID.SUBTYPE_CODE,DES.DESCRIPTION_TEXT,BID.SUBTYPE_CODE,BID.RATE_TYPE;
-
-
COMMIT;
-
-
UPDATE CHN_BILLREFDUMP3_T1_FX SET STAT= 1 WHERE ROWID = CC.TMP_ROWID;
-
-
COMMIT;
-
-
i:=i+1;
-
-
END LOOP;
-
-
DBMS_OUTPUT.PUT_LINE ('Done');
-
-
END;
-
/
-
-
-
-
I truncate since the space given for user id is very limited and i have to run this query is 15 servers using DBlinks.Hence truncating the tablespace is the only way for me.
It was truncating my table size previously but now suddenly i have this problem.
You might be facing the problem due to delete operation performed nearly 500 times. Make sure you re build your indexes so that the orphan leaf are removed from the Indexes for atleast each 100 delete operations.
Hmm.. thanks for the reply....
Actually the script is really fast and without giving Truncate command there is no other option to reduce the table size to default while creating it...
This was working until 2 days before.I heard there is an option as "Recycle bin ON" which stops the table size from getting reduced....
That can be the reason. Just try setting RECYCLEBIN to OFF either at system or session level and run your procedure and check.
Yeah got it guys....... The trick is to create the table with initial storage space specified.
Ex .. Create table tmp storage(initial 50M)
so when truncating oracle returns the table space to be 50M .This applies in 10G.
Thanks for the support. :)
You are Welcome :)
Do post back in case of any further issues
Moderator
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Gordon |
last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to
delete rows from t1 based on criteria on the t table and a relationship
between t ad t1 (in this case the id column). In the results below, I
would think that the delete should have deleted row 1 {1 5 me) and not
row 3 (1 5 they) when I run this statement
delete t1 from t, t1 where t.id = t1.id and t.id=1 and t.name = 'me';
Any ideas on why row 2 is deleted?
|
by: martin |
last post by:
Hi,
We have a heavily used production server and a table which logs every
hit on a web site. This table has grown large over time and we want to
clear it down as efficiently as possible. We would like to issue a
truncate table statement, but with millions of rows we are a bit wary
of how this will affect server performance. The alternative is to
delete is stages using rowcount but of course this will generate a
large amount of logging....
|
by: Fred |
last post by:
Hi, my database size has grown out of control and I need help with the
following issues. (I am very new to databases)
I am storing financial tick data in one of the tables and after two months
the database has grown to 30GB. I do not need a permanent record of this
tick data after it has been processed and tried to remove all rows from this
table (delete from Tickdata), however sql does not take kindly to removing
millions of rows and...
|
by: LineVoltageHalogen |
last post by:
Greeting All, I have a stored proc that dynamically truncates all the
tables in my databases. I use a cursor and some dynamic sql for this:
......
create cursor
Loop through sysobjects and get all table names in my database.
....
exec ('truncate table ' + @TableName)
|
by: Hervé Piedvache |
last post by:
Bug or problem with PostgreSQL ?
version
---------------------------------------------------------------
PostgreSQL 7.4.3 on i686-pc-linux-gnu, compiled by GCC 2.95.4
select * from my_table;
id | login | passwd | state | email
--------------+-----------+------------+-------+------------------
(0 rows)
| |
by: pankaj_wolfhunter |
last post by:
Greetings,
I have an application that need to get all the user
defined child tables first before their parents.
I wrote a query, given in this newsgroup only, as below
SELECT o.name
FROM sysobjects o
WHERE o.type='U'
ORDER BY case WHEN exists ( SELECT *
FROM sysforeignkeys f
|
by: polocar |
last post by:
Hi,
I'm writing a program in Visual C# 2005 Professional Edition.
This program connects to a SQL Server 2005 database called
"Generations" (in which there is only one table, called
"Generations"), and it allows the user to add, edit and delete the
various records of the table.
"Generations" table has the following fields:
"IDPerson", NamePerson", "AgePerson" and "IDParent".
A record contains the information about a person (his name, his...
|
by: Sala |
last post by:
Hi
I want to truncate all data in database ... pls help me how i ll
truncate?
|
by: Lennart |
last post by:
Any thoughts on the following scenario anyone?
During a performance test I discovered that the application asked one
specific query extremely often. It turned out that this particular
query where asked 25/50/100 or 200 times from a "htmlpage", dependent
of user preferences. I figured that using a global temp table, looping
and inserting, then join would do the trick.
However, it turned out that this killed performance totally. Why,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |