Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2015
    Posts
    1

    Unanswered: Script to Delete Historic Data

    Hi,

    I'm fairly new to writing my own scripts, and need some help.

    I've been tasked to implement a scheduled script (running once a day) that deletes data older than 125 days from a rather big partitioned table.

    There is a column in the table that holds the transaction date which can be used in the query, or alternatively I'd like to use the high value of the table partition, or maybe even the partition position.

    Each partition contains around 40 million rows, so performance is also a concern.

    My current query:

    delete from USER.TABLE where trunc(TRANS_DATE) = '02-DEC-13';


    Stephan

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >delete from USER.TABLE where trunc(TRANS_DATE) = '02-DEC-13';

    NEVER rely on implicit datatype conversion.
    '02-DEC-13' is a STRING & TO_DATE() function should be used.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Code:
    delete from your_table
    where trans_date < trunc(sysdate) - 125
    might be a better option. TRUNC(TRANS_DATE) you used won't use index (if any) on the TRANS_DATE column. Which, furthermore, means that - if you don't already have an index on TRANS_DATE, create it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •