hartwig has asked for the wisdom of the Perl Monks concerning the following question:

Hi Folks, this time I am looking for some advice regarding Oracle databsae tables. I have a "huge" database.
What I plan to do is to extract consistent table entries and inject these into a test schema.
Are there any modules around that do the trick?
Wishing you well Hartwig


I have to be more precise a asume:
Given the two tables: table (v)alue
Primary key vid:
table (h)ierachy
foreign Key 1 -> vid
foreign Key 2 -> vid

It is pretty easy to build a tree like structure. So I am planing to copy the tree structure into another schema. I think that is not possible via exp tool - and connect prior by is dead slow on oracle 9i

Replies are listed 'Best First'.
Re: deep copy of complex database tables
by Thilosophy (Curate) on Jun 21, 2005 at 11:04 UTC
    You may want to look at Oracle-supplied utitilies, in particular exp, which dumps consistent snapshots of parts (or the whole) of the database. You can then later import these with the imp utility.

    If you are only concerned with a few tables, you can just do something like the following (which would also work across database links if you set those up):

    create table testschema.blah as select * from realschema.blah;

    What do you mean by "complex" tables that need a "deep copy"?

Re: deep copy of complex database tables
by merlyn (Sage) on Jun 21, 2005 at 10:37 UTC
    I'm not an Oracle guy, but in PostgreSQL, I can say "CREATE DATABASE foo_test TEMPLATE foo;", and Pg creates a snapshot into my test database. For this to work, nobody can be attached to the source database.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: deep copy of complex database tables
by ghenry (Vicar) on Jun 21, 2005 at 11:05 UTC

    Update: Thilosophy beat me to it ;-)

    Why reinvent the wheel?

    You should use the oracle utilities for this, which you can script via perl.

    You need to use Oracle's exp utility. If you have admin rights on the DB, then you can export objects from one schema and import into another.

    $ORACLE_HOME/bin/exp help=yes for export syntax

    $ORACLE_HOME/bin/imp help=yes for import syntax

    I hope I am not barking up the wrong tree.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!
Re: deep copy of complex database tables
by DrHyde (Prior) on Jun 22, 2005 at 07:57 UTC
    If you *do* fancy reinventing the wheel, look at the following tables in the data dictionary:
    • user_tables
    • user_tab_columns
    • user_constraints
    • and no doubt a few others
    to figure out what tables you need to copy, then CREATE TABLE foo ... AS SELECT ...
      Before writing nifty comments about reinventing- try to read the question carefully :~| -
      Assume you have a graph-structure which is circular and fairly easy to construct with the given two tables - it is non trivial to extract this structure from the graph. As I mentioned - what I like to have is a deep copy (including all 'sub-table-entries') - any ideas?