Delete rows older than given number of hours

Hi,
I have a table student which contains the following columns
ID Number(5)
Name varchar2(20)
Strt_Time timestamp(6)
Strt_time is the timestamp when the particular row is inserted in the table.
I need a query to delete all the rows inserted before given particular number of hours.
For Example. If i pass the input paramter as 2 all the rows inserted before 2 hours from now should get deleted.

Hi,
Here's one way:
DELETE  student
WHERE     strt_time < SYSTIMESTAMP - INTERVAL '2' HOUR
;Or, if you're getting a NUMBER parameter like :num_hours, then
DELETE  student
WHERE     strt_time < SYSTIMESTAMP - NUMTODSINTERVAL (:num_hours, 'HOUR')
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
In the case of a DML operation (such as DELETE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table after the DML.
Explain, using specific examples, how you get those results from that data.
If your results depend on the current time and/or parammeters, then give a couple of different examples using the same sample data. For example "If I run this at 11:00 on January 3, 2013, with :num_hours=12, then the table should be left with ... but if I run it at 13:00 on January 3, 2013, with :num_hours= 24, then I should get ..."
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002}

Similar Messages

  • Query for deleting rows older than 25?

    Am trying to delete rows older than 25... How would the query for this be like? I tried this "DELETE FROM DB LIMIT 25,100" But getting errors...

    what is older than 25? Does it mean with id greater then 25?
    then you should have a query like
    DELETE FROM tableName WHERE id > 25

  • How to delete data older than three years from DSO

    Hi  all,
    We needs to keep historical data in the DSO only for three years. One way of doing this is by selective deletion we can delete data older than three years but we want to make it authomated. Is it possible to add a process or ABAP program to delete data older than three years.
    If it is p[ossible by ABAP code then can you please give me sample code.
    Many Thanks in advance.
    Harman

    Some time for in case of huge volume of data selective deletion is not works, Try for "prunning" option.
    It's work as follows
    1)     Create DSO which is same replica of your Source DSO.
    2)     Create two transformation
         a) from Source DSO to Copy DSO
         b) Another is from Copy DSO to Source DSO
    3)     Transprort Last 3 years records to Copy of Source DSO using DTP Filter range for time.
    4)     Once data loading from Source DSO to Copy DSO get completed delete all data from Source DSO.
    5)     Now load data from Copy DSO to Source DSO.
    6)     After complete loading delete entire data from Source DSO.
    I use prunning process to one of my client and it's work perfectly.
    Regards,
    Sushant
    +919820849482

  • Delete messages older than a date except personal folder

    Hello everyone,
    I have been spending a lot of time searching and testing how to delete all items older than 6 months in a user mailbox, but this rule it cannot be applied just one personal folder named "personal". I have been reading about retention policy and
    retention policy tags, but I can't figure out how to use that to keep all items older than 6 month in personal folder.
    could anyone tell me if I am right with retention policy or it's better other way?
    thank you in advice

    Hi,
    In Outlook client, we can set AutoArchive for all folders to delete all items older than 6 months except for “Personal” folder one by one.
    If you want to use retention policy in Exchange side, we can use retention tags and retention policies to have a try. there are three types of retention tags:
    Default policy tag (DPT), Retention policy tag (RPT), Personal tag.
    For your scenario, we can create a personal tag applied for this Personal folder. For example,
    delete messages older than 3 years for this personal folder. Then apply this personal tag for Personal folder in Outlook. And the Personal folder items are all tagged. After that, we can
    applying default policy tags (DPTs) to mailboxes to manage the retention of all untagged items.
    Personal suggestion, since the delete action is only used for one specific mailbox, I suggest we can use AutoArchive in Outlook side to achieve it.
    Regards,
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]
    Winnie Liang
    TechNet Community Support
    Hi Winnie Liang,
    Thank you for answer. I would like to do all tasks from exchange side, so I know how to apply a retention policy to a mailbox for deleting all older than 6 months. But how can I apply the personal policy tag to a personal folder's users?
    All involved users in this requirement are warned that they must let all personal messages in "personal" folder named "personal".
    regards

  • HT3275 I've 1.85TB empty space on my time Machine, but it only backs up to the beginning of the previous month. it should have weekly back-ups for every month before that. Any ideas why it deletes stuff older than a month?

    I've 1.85TB empty space on my Time Machine, but it only retains back-ups to the beginning of the previous month. I should be able to access weekly back-ups for every month before that until the disk is full. Any ideas why it deletes stuff older than a month?
    Thanks, Rigby.

    If you are using Ethernet to connect your Mac to the Time Capsule, are you allowing at least 2-3 minutes for Time Machine to fully load when you open the application to see your backups?
    If you are using wireless to connect, you may need to allow 8-10 minutes or longer for everything to fully load, depending on the speed of your wireless connection.
    If you see only white time "bars" on the timeline at the right of the screen, you are seeing temporary backups. Permanent backups are displayed with purple "bars".

  • Outlook 2013 Deletes mail older than 30 days in deleted items folder

    Environment: Outlook 2013 and Exchange 2007 (fully patched)
    One user has an issue where only 30 days worth of email is maintained in the deleted items folder. Every day, any email sent to deleted the previous day, will be gone.
    Any thoughts?

    Hi,
    Outlook itself doesn't auto-delete anything. It could be something that's automatically being done by the server.
    Let's first check the behavior on Outlook Web App (OWA), and see if issue persists.
    If issue repro's on OWA, then it's something on Exchange server side, I would suggest you post the question in
    Exchange server forum for further assistance.
    If issue doesn't repro on OWA side, it might be something on Outlook client side that deletes emails from the trash. For this scenario, I would suggest you first check if he/she has
    AutoArchive configured for the deleted folder which might delete messages older than a certain period of time.
    Please feel free to post back with any findings.
    Regards,
    Ethan Hua
    Forum Support
    Come back and mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback on our support, please click
    here

  • Deleting backups older than a month

    Hi all,
    I'm trying to delete backups that are older than a month. I've performed the following steps.
    1. Click on time machine
    2. Navigate to a month ago
    3. Navigate to "Macintosh HD" and select all items
    4. Click on the gears the "Delete all backups .."
    This delete all backups, even my current ones. How can I delete just "old" versions from a snapshot in time (say x) back to the beginning of backups and keep everything with time > x?
    Thanks,
    Todd

    +That won't screw up the database will it?+
    Probably. Time Machine uses hard links to keep track of its previously backed up files. You can read how Time Machine uses hard links in this Ars Technica review.
    http://arstechnica.com/reviews/os/mac-os-x-10-5.ars/14
    To make sure you keep the hard links intact launch the Time Machine browser from the dock. Click on your hard drive in the sidebar. Don't select any folders or files in the window. Use the white ladder lines on the right to navigate to the backup you wish to delete. Click on the button with the gear and select Delete Backup.

  • PowerShell: Script to delete files older than X days

    Hi All,
    I am testing a script to delete files and I have it written down in my notepad as below:
    $foldername = $args[0]
    $maxage =      $args[1]
    gci $foldername | Where-object {($_-is [io.fileinfo]) -and ($_.lastwritetime -lt (get-date).AddDays(-$maxage) ) } |
    remove-item -whatif
    Question: When i try to run the script and  pass the parameters $foldername and 30 it doesn't return anything. I am expecting it to return with -Whatif
    To execute the script I wrote:
    .\myscipts\del.ps1  cmd2 30
    cmd2 is the name of the folder in my drive and 30 is ($maxage)  number of days old.
    Thank-you
    SQL 75

    Thansks jrv, looks good! One more thing I wanted to ask do you know what it means by the error:
    "An Empty Pipe Element is not Allowed" I altered my script a bit but it gives me this error. and I am passing no parameters when i call the script. My Script I created is below:
    $name = $args[0]
    $chew = $args[1]
    IF ( $args.count -lt 2)  { Write-host "Please provide 2 parameters for this to work"
                    exit 1 }
    GCI $name | Where-object { $_-is [io.fileinfo]  -and ($_.lastwritetime -lt (get-date).AddDays(-$chew))}
     | remove-item -whatif
    Thank-you
    SQL 75

  • Delete emails older than 3 months sent to a distribution group

    Hi,
    Have a strange request hopefully someone can help me with.
    We have Exchange 2010 on site. There are a large number of casual staff who are only at work for a few months of the years, then are away for a long period. These staff are still receiving all of the Everybody emails that are sent out, causing their mailboxes
    to fill up and stop receiving emails.
    I have tried the usual searches and have found solutions for deleting email with specific titles and for specific dates; but I cannot find any information on being able to delete based on the 'To' field of an email.
    My query is -
    Is there a way to delete emails from all mailboxes in an organisation that have been sent to a specific distribution group that are over three months old?
    All help is always gratefully received.
    Thanks,
    Peter D.

    Hi,
    I have found a solution to this issue.
    Am posting it for when i need it later, or if it helps anyone else.
    Using Powershell, i use the following code to be able to search using the To field, which in this case is the name of the distribution group.
    #Add Exchange 2010 snapin if not already loaded
    if (!(Get-PSSnapin | where {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"}))
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue
    get-Mailbox | search-mailbox -searchquery to:"DistributionGroup" -DeleteContent
    Now just to add the date variable...

  • Bb calendar -on device deletes entries older than 3 months

    when i sync all from outlook is there on the device - then for some reason - all but the last 3 months are deleted!  help!  thanks, BeAwesome

    oh, yes, i've gone through the advanced tabs and it's synchronizing both ways.
    every time i save the data and redo the whole process - everything is there.  then somehow the curve's calendar entries disappear except the last 3 months.  all future entries are still there
    i'm using version 4.3.0 15 (but have windows xp - not vista - is this a problem)
    on the curve i clicked on calendar - options - but there is no 'keep appointments' field for me to select any options.
    your assistance is greatly appreciated!
    BeAwesome

  • Mac Mail deleting mail older than 1 month old

    Mac Mail is deleting mail, from my Inbox, after 1 month old. I can't find the settings for deletion or archiving. I have not selected archiving either. Any ideas?
    Thanks

    Hello Steve:
    I think you misunderstood my post. I was not talking about the delete trash setting in Apple's Mail application. Many (most?) E-mail providers have settings in their applications to automatically delete mail. This has nothing to do with Apple's mail application. I know nothing about Mobile Me or Mac mail, but what I was suggesting was that those might have a setting someplace.
    Apple's mail application did not, on its own, to delete mail. There is no setting in that application that I am aware of that would cause that to happen.
    Barry

  • Excahange 2007 Need to permanently delete all emails older than x years

    Cant get to the 2007 forum so don't know if this is the right place.
    Trying to permanently delete all mail older than 4 years from our Exchange 2007 server. I have worked with Powershell in 2010 (Exchange) 
    but I cannot run due to some restrictions with 32/64 bit powershell limitations in exchange 2007.
    I have searched google and these forums -- there has to be an easy way to do this or someone that can point me in the right direction.
    Thanks in advance

    Hi,
    In Exchange 2007, you can use the following cmdlet to delete emails older than the mentioned date from a mailbox.
    Export-Mailbox -Identity xxx -StartDate "xx/xx/xxxx" -EndDate "xx/xx/xxxx" -DeleteContent
    If you need to perform this on a set of mailboxes, paste all display names to a TXT file, name is as "test.txt". Run the following cmdlet.
    Get-Content test.txt | Export-Mailbox -StartDate "xx/xx/xxxx" -EndDate "xx/xx/xxxx" –DeleteContent –Maxthreads 4
    Hope this can be helpful to you.
    Best regards,
    Amy Wang
    TechNet Community Support

  • ORA-01427 single-row subquery returns more than requested number of rows

    Hi All,
    SR#3-5155460391
    When opening the Expense report form the given error occurs.
    This is happening with only one employee.
    The condition could not be evaluated because of error ORA-01427
    single-row subquery returns more than requested number of rows.
    query is:
    select pea.segment5
    from
    per_all_assignments_f paf,
    pay_personal_payment_methods_f ppm,
    pay_external_accounts pea,
    fnd_application fap,
    fnd_id_flex_structures ffs
    where
    paf.person_id=:employee_id
    and paf.primary_flag='Y'
    and paf.assignment_type='E'
    and trunc(sysdate) between paf.effective_start_date and paf.effective_end_date
    and ppm.assignment_id=paf.assignment_id
    and trunc(sysdate) between ppm.effective_start_date and ppm.effective_end_date
    and ppm.attribute2='Y'
    and pea.external_account_id=ppm.external_account_id
    and pea.id_flex_num=ffs.id_flex_num
    and fap.application_short_name='PAY'
    and ffs.application_id=fap.application_id
    and ffs.id_flex_code='BANK'
    and ffs.id_flex_structure_code='GB_BANK_DETAILS';
    Thanks,
    Shikha
    Edited by: user10456902 on Feb 3, 2012 1:57 AM

    Hi,
    First try to find pea.external_account_id from per_all_people_f,per_all_assignments_f,fnd_application.fnd_id_flex_structures etc
    and then find
    SELECt pea.segment5
    FROM pay_external_accounts pea
    WHERE pea.external_account_id = : external_account_id -- derived from SQL1
    and check how many rows are returned

  • How to count the number of deleted rows processed

    Sybase ASE version: 15.7-SP52
    Hi all,
    I have a delete statement that will potentially delete millions of rows
    DELETE from TAB_A where COL_A='Y'
    The delete is long, at some point I'd like to know how many rows were deleted.
    If I do SELECT COUNT(*) from TAB_A where COL_A='Y', the query should be locked because of the exclusive-lock held by the DELETE in progress.
    If this is the case, how can I actually count the number of rows deleted so far?
    Thanks all
    Simon

    Simon
    For  deleting significant number of rows best practice is to delete rows in small batches of known size (e.g. 10 K) inside a while loop. 
    This keeps transaction log from filling up as well.
    Also between two iterations of delete you can give some wait to make sure that you do not monopolize the server. Sleep could be for a fixed number of seconds (e.g. 5) or for randomized number say from 1 to whatever makes sense.
    Typically "set rowcount " is used to set up the batch size and "waitfor delay" to sleep between iterations.
    Global variable @@rowcount gives yo actual rows deleted. For the last batch this may be lower than the batch size you set up.
    HTH
    Avinash

  • ORA-01422- exact fetch returns more than requested number of rows in D2K Report

    Hi All,
    Greetings.
    I am using a report which is being called from the from in one of my application. The report is working fine from quiet a long time. I have an error with a particular record alone and it is working fine for all other records.
    When I try to run the report, I am getting the error as Rep-1401- 'cf_vatformula' : Fatal pl/sql error occured.
                                                                                ORA-01422- Exact fetch returns more than requested number of rows.
    I opened the formula column and run the sql codes that are used in the formula column cf_vat and all of them are working fine. None of them are fetching more a single row. But, when I run the report, I am getting the same error as mentioned above.
    Please help me resolve the issue ASAP. Thanks in Advance.
    Regards,
    Bhaskar.

    Hi InoL,
    Thanks for your time.
    I am sure that there is no other procedure used in cf_vatformula. It has select queries in and all of them are fetching the data not more than a single row.
    I have tested each and every select query with every possible output.
    Regards,
    Bhaskar.

Maybe you are looking for

  • Help looking for a database

    For years I have relied upon Appleworks for my simple database issues but have not hit a snag. The nature of the data I am now storing requires large numbers of characters to be stored in a single field. Appleworks has a character limit of approx 500

  • How to get backed up apps back after restoring it to factory settings

    Hi, I recently tried to update to the new 3.2.1 update, but something happened and it restored my iPad back to factory settings, the good thing was that I backed all my apps before I tried to update, but now I can't figure out how to get them back. I

  • Wiping hard drive clean

    I'm preparing to sell my iBook G3 and would like to find out how to clean everything on my hard drive, or at least have the computer the way it was when I received it from the factory. Any suggestions????

  • Adobe Photoshop crashes!

    So I have had Photoshop CS3 for a while and then one day when I tried to access it again it decided to crash upon loading it. It has worked before and I have tried removing the preferences file but nothing seems to help. I have even looked all over t

  • Safari randomly shuts down.

    Sometimes I will be browsing or doing something on safari on my touch and it will just randomly close. I have update 1.1.4. Anyone know why? Cheers