how to create procedure to delete rows from STATS$SNAPSHOT in Oracle

Posted on 2009-12-21
Last Modified: 2013-12-18
Hi Experts,

I'm about to create a simple stored procedure in oracle that should delete data in the table called STATS$SNAPSHOT where snap_time is older than x days.

when i run this query:
delete from STATS$SNAPSHOT where snap_time < (sysdate - 2);
 it works fine, but when I run my procedure (EXECUTE DelStatspackData(2);) then i get some error:
Error starting at line 2 in command:
EXECUTE DelStatspackData(1);
Error report:
ORA-06550: line 1, column 7:
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.

Could you please help me with that?

create or replace PROCEDURE DelStatspackData (i IN NUMBER) IS


  delete from STATS$SNAPSHOT where snap_time < (sysdate - i);

end DelStatspackData;

Open in new window

Question by:delmandiyar
    LVL 15

    Expert Comment

    by:Franck Pachot
    - After creating the procedure, use 'show errors' to see errors.
    - you should use sppurge.sql script to purge statspack data.
    LVL 14

    Assisted Solution

    may by your procedure is invalid check and compile it.. for more information check this link

    Author Comment

    Hi, thanks for your answers,

    I'm using Oracle SQL Developer. When i create my procedure, it tells me that procedure created with warning, but when  i complied i get this error:
    Error(7,4): PL/SQL: SQL Statement ignored.
    Error(7,16): PL/SQL: ORA-00942: table or view does not exist.

    what i need is a procedure that deletes data in STATS$SNAPSHOT older than x days. x should be a parameter for my procedure. could u please help me with that??
    LVL 15

    Accepted Solution

    The procedure owner must have direct delete grant on that table (direct - nor via a role)

    Author Comment

    Franckpachot you right, I realised that just 5 minutes before I saw your answer.

    But thanks anyway to all of you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Introduction A previously published article on Experts Exchange ("Joins in Oracle", makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
    Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
    This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
    Via a live example, show how to take different types of Oracle backups using RMAN.

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now