473,811 Members | 3,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to reduce table size using delete or truncate statement in 10G

15 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. BEGIN
  2.  
  3. i:= 0;
  4.  
  5. FOR CC IN NLD LOOP
  6.  
  7. DELETE FROM CHN_BED5A_T4_FX ;
  8.  
  9. COMMIT;
  10.  
  11. DELETE FROM CHN_BED5B_T4_FX ;
  12.  
  13. COMMIT;
  14.  
  15.  
  16. if i=500
  17. then 
  18. EXECUTE IMMEDIATE('TRUNCATE table CHN_BED5A_T4_FX');
  19. EXECUTE IMMEDIATE('TRUNCATE table CHN_BED5B_T4_FX');
  20. i:= 0;
  21. end if;
  22.  
  23. commit;
  24.  

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.....
Dec 21 '09 #1
8 7718
OraMaster
135 New Member
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
Dec 21 '09 #2
amitpatel66
2,367 Recognized Expert Top Contributor
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
Dec 21 '09 #3
ananthaisin
15 New Member
Hi ,

I am sorry for not pasting the complete code... here is the complete one...

Expand|Select|Wrap|Line Numbers
  1. SET SERVEROUTPUT ON;
  2.  
  3. DECLARE
  4.  
  5. i number;
  6.  
  7. CURSOR NLD IS
  8. SELECT A.ROWID AS TMP_ROWID,A.* FROM CHN_BILLREFDUMP3_T1_FX A WHERE A.STAT=0 AND A.STRM=1;
  9.  
  10.  
  11. BEGIN
  12.  
  13. i:= 0;
  14.  
  15. FOR CC IN NLD LOOP
  16.  
  17. DELETE FROM CHN_BED3A_T4_FX ;
  18.  
  19. COMMIT;
  20.  
  21. DELETE FROM CHN_BED3B_T4_FX ;
  22.  
  23. COMMIT;
  24.  
  25.  
  26. if i=500
  27. then 
  28. EXECUTE IMMEDIATE('TRUNCATE table CHN_BED3A_T4_FX');
  29. EXECUTE IMMEDIATE('TRUNCATE table CHN_BED3B_T4_FX');
  30. i:= 0;
  31. end if;
  32.  
  33. commit;
  34.  
  35.  
  36.  
  37. INSERT /*+ append */ INTO CHN_BED3A_T4_FX
  38. SELECT /*+ ordered*/ 0,
  39. A.JURISDICTION,A.RATE_DT,A.PRIMARY_UNITS,A.SECOND_UNITS,A.THIRD_UNITS,A.RATED_UNITS,
  40. A.AMOUNT,B.MSG_ID,B.MSG_ID2,B.MSG_ID_SERV,B.SPLIT_ROW_NUM,B.ACCOUNT_NO,B.SUBSCR_NO,
  41. B.SUBSCR_NO_RESETS,B.BILL_REF_NO AS INDEX_BILL_REF,B.BILL_REF_RESETS,B.BILLED_AMOUNT,
  42. B.DISCOUNT,B.TRANS_DT,B.TYPE_ID_USG
  43. FROM chn_cdr_data_CU3 A,chn_cdr_billed_CU3 B
  44. WHERE a.CDR_DATA_PARTITION_KEY=b.CDR_DATA_PARTITION_KEY and
  45. 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;
  46.  
  47. COMMIT;
  48.  
  49.  
  50. INSERT /*+ append */ INTO CHN_BED3B_T4_FX
  51. SELECT /*+ ordered*/ MSG_ID,MSG_ID2,MSG_ID_SERV,BILL_REF_NO,COUNT(*) FROM chn_cdr_billed_CU3 WHERE BILLED_AMOUNT>0 AND
  52. BILL_REF_NO=CC.INDEX_BILL_REF GROUP BY MSG_ID,MSG_ID2,MSG_ID_SERV,BILL_REF_NO;
  53.  
  54. COMMIT;
  55.  
  56. --DUMPING ALL THE CALLS WITH CALL SPLIT =1  EVEN IT IS AIRTIME OR PSTN
  57.  
  58. 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
  59. AND A.MSG_ID=B.MSG_ID AND A.MSG_ID2=B.MSG_ID2 AND  B.MSG_ID_SERV=A.MSG_ID_SERV) ;
  60.  
  61. COMMIT;
  62.  
  63. 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
  64. AND A.MSG_ID=B.MSG_ID AND A.MSG_ID2=B.MSG_ID2 AND  B.MSG_ID_SERV=A.MSG_ID_SERV) WHERE
  65. ( CNT=0 OR CNT IS NULL) AND A.TYPE_ID_USG IN ( SELECT SUBTYPE_CODE FROM mis.CHTYPEMAST2 WHERE UPPER(ITEM_DESCRIPTION) LIKE '%AIR%'
  66. OR UPPER(ITEM_DESCRIPTION) LIKE '%HIERARCHY%');
  67.  
  68. COMMIT;
  69.  
  70. DELETE FROM CHN_BED3A_T4_FX WHERE CNT IS NULL;
  71.  
  72. INSERT /*+ append */ INTO CHN_BILLBKUP3BDUMP_T3_FX
  73. SELECT /*+ ordered*/ SUBSCR_NO,SUBSCR_NO_RESETS,TYPE_ID_USG,INDEX_BILL_REF,JURISDICTION,SUM(PRIMARY_UNITS) AS ACTDURN,
  74. SUM(RATED_UNITS) AS CHARGED_UNITS,COUNT(*) AS CALLCOUNT ,SUM(SECOND_UNITS) AS ROAMDURN
  75. FROM CHN_BED3A_T4_FX
  76. GROUP BY SUBSCR_NO,SUBSCR_NO_RESETS,TYPE_ID_USG,INDEX_BILL_REF,JURISDICTION;
  77.  
  78. COMMIT;
  79.  
  80. INSERT /*+ append */ INTO CHN_BILLBKUP3_T2_FX (INDEX_BILL_REF,SUBSCR_NO,SUBSCR_NO_RESETS,  SUBTYPE_CODE, RATE_TYPE, REVENUE_TYPE,
  81. ITEM_CODE,  ITEM_DESCRIPTION,AMOUNT,TAX,DISCOUNT, NET_AMT_IN_RUPEES)
  82. SELECT  /*+ ordered*/
  83. BID.BILL_REF_NO,BID.SUBSCR_NO,SUBSCR_NO_RESETS,BID.SUBTYPE_CODE,BID.RATE_TYPE,
  84. DECODE(BID.TYPE_CODE,2,'RC',3,'NRC',1,'PAY',7,'USG',4,'ADJ',6,'UC',TYPE_CODE,'OTH') AS REVENUE_TYPE,
  85. BID.SUBTYPE_CODE AS ITEM_CODE,
  86. DES.DESCRIPTION_TEXT AS ITEM_DESCRIPTION,
  87. SUM(BID.AMOUNT) /100     AS AMOUNT           ,
  88. SUM(BID.TAX )       /100         AS TAX   ,
  89. SUM(BID.DISCOUNT)    /100      AS DISCOUNT     ,
  90. SUM(BID.AMOUNT+BID.TAX+BID.DISCOUNT) /100 AS NET_AMT_IN_RUPEES
  91. FROM  chn_bill_invoice_detail_CU3 BID, chn_descriptions_CU3 DES
  92. WHERE BID.BILL_REF_NO = CC.INDEX_BILL_REF
  93. AND BID.subtype_code <>'-1050'
  94. AND BID.DESCRIPTION_CODE = DES.DESCRIPTION_CODE(+)
  95. AND BID.TYPE_CODE IN (2,3,4,7)
  96. 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'),
  97. BID.SUBTYPE_CODE,DES.DESCRIPTION_TEXT,BID.SUBTYPE_CODE,BID.RATE_TYPE;
  98.  
  99. COMMIT;
  100.  
  101. UPDATE CHN_BILLREFDUMP3_T1_FX SET STAT= 1 WHERE ROWID = CC.TMP_ROWID;
  102.  
  103. COMMIT;
  104.  
  105. i:=i+1;
  106.  
  107. END LOOP;
  108.  
  109. DBMS_OUTPUT.PUT_LINE ('Done');
  110.  
  111. END;
  112. /
  113.  
  114.  
  115.  
  116.  
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.
Dec 22 '09 #4
amitpatel66
2,367 Recognized Expert Top Contributor
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.
Dec 22 '09 #5
ananthaisin
15 New Member
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....
Dec 23 '09 #6
amitpatel66
2,367 Recognized Expert Top Contributor
That can be the reason. Just try setting RECYCLEBIN to OFF either at system or session level and run your procedure and check.
Dec 23 '09 #7
ananthaisin
15 New Member
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. :)
Dec 31 '09 #8
amitpatel66
2,367 Recognized Expert Top Contributor
You are Welcome :)
Do post back in case of any further issues

Moderator
Dec 31 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6462
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?
3
4528
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....
5
2395
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...
3
8663
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)
2
1749
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)
5
1344
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
6
3862
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...
14
12300
by: Sala | last post by:
Hi I want to truncate all data in database ... pls help me how i ll truncate?
3
2454
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,...
0
9730
marktang
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...
0
10651
Oralloy
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...
0
10392
jinu1996
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...
0
10136
tracyyun
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...
1
7671
isladogs
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...
0
6893
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();...
0
5555
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...
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.