Solved

Count records...

Posted on 2014-02-17
5
470 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 142

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 142

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
logs for inetpub time stamps are off 1 22
PL/SQL Display based on value 4 27
ODBC in excel 2016 in Windows 10 via VBA 16 74
migration MS SQL database to Oracle 30 61
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

770 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