Solved

Count records...

Posted on 2014-02-17
5
471 Views
Last Modified: 2014-02-18
Hi,
I developed DB in ORACLE 11g XE and since there is a limitation (11GB), the DB is keeping only the records with certain criteria. The records are deleted (with stored procedure) once in a day (23:59)...
The client requested to have statistics / reports on the records.
I think that it will be the best solution to count the deleted records and write the count in one table with time stamp... Can someone help me?
Thank you in advance,
Best,
Andreja
0
Comment
Question by:andrejaTJ
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 39864894
Perhaps you could persuade your client to PURCHASE at minimum the Standard edition.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 233 total points
ID: 39864900
directly after the delete, use SQL%ROWCOUNT value.
this would be the pl/sql draft to start with:
DECLARE 
  v_rows NUMBER;
BEGIN
DELETE yourtable WHERE .... ;
  v_rows := SQL%_ROWCOUNT;
 INSERT INTO your_log_table ( datetime, rows_deleted ) VALUES ( SYSDATE, v_rows);
 COMMIT;
END; 

Open in new window

0
 

Author Comment

by:andrejaTJ
ID: 39864914
Thank you for your prompt reply.
But the "DELETE yourtable WHERE" is not applicable here...
Can you please help me without the "DELETE yourtable WHERE"?I will schedule job prior the one that is calling the DELETE stored procedure...
Thank you,
Best,
Andreja
0
 
LVL 29

Assisted Solution

by:MikeOM_DBA
MikeOM_DBA earned 117 total points
ID: 39864927
You may need to add Guy's suggested code inside the DELETE stored procedure.
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 233 total points
ID: 39864935
exactly.
you cannot count "outside" the stored procedure on how many records you deleted exactly.

well, you COULD do the count of the records to be deleted using the same condition the stored procedure is doing, but then you will just waste db power to do 2 times the same thing.
you COULD also counter the number of records in the table before and after the procedure, but this will give erroneous results if during that time, new records are added.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question