• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to copy old data from one table to another in same database

 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I need to copy old data from a table to another. Old data as in data older than 3 months, there's a column in the table which I can use as reference for time. How do I write the copying code using SQL*PLUS?

I found the following which seems to copy the entire table, so how do I modify it to copy rows older than 3 months?

Also, how do I get this to be automated say once a month?

Any help in pointing me in the right directions is appreciated!

Thanks!

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chengwei,

It's quite easy:




But do you really mean copy or rather mean move?

The problem is if you copy the reecords then on the next run this script would copy them again - unless you have a primary/unique key, then it would just throw an error.

Maybe it would be advisable to delete or at least mark the already copied rows.


John

 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

You're right, it should have been move instead of copy! I'll give it a try.

Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic