terrykhatri531 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I am no perl programmer however I need to create a script that creates a desired number of tables with desired number of inserts per table, here is the code :
#!/usr/bin/perl use DBI; $tables=100; $rows=10000; $count=1 if (!($dbh = DBI->connect ('DBI:Oracle:orcl',"hr","hr"))) { die ("Failed to connect to database: " . DBI->errstr); }; $sql = "CREATE TABLE test_data($count)(". "id PRIMARY KEY,". "group_id NOT NULL,". "created_at NOT NULL,". "text NOT NULL) AS ". "SELECT ". "rownum,". "MOD(rownum, 5),". "TO_DATE('1-jan-07', 'dd-mon-yy') + INTERVAL ' +1' MINUTE * rownum,". "CAST ('xyz' || rownum AS VARCHAR2(50)) ". "FROM dual ". "CONNECT BY LEVEL <= $rows"; while ($count<$tables) { if (!($dbh->do ($sql))) { die ("Failed to insert row: " . DBI->errstr); }; $count++; } $dbh->commit; $dbh->disconnect;
It should create tables from test_data1 to test_data100
Can someone be please kind enough to correct the code.
Thank you very much in advance.
Rgds
Terry
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Need help to correct a simple script
by marto (Cardinal) on Jan 07, 2013 at 15:42 UTC | |
by space_monk (Chaplain) on Jan 08, 2013 at 09:52 UTC | |
Re: Need help to correct a simple script
by space_monk (Chaplain) on Jan 07, 2013 at 15:57 UTC | |
Re: Need help to correct a simple script
by blue_cowdawg (Monsignor) on Jan 07, 2013 at 15:36 UTC | |
Re: Need help to correct a simple script
by space_monk (Chaplain) on Jan 07, 2013 at 16:08 UTC | |
by terrykhatri531 (Novice) on Jan 07, 2013 at 18:36 UTC |
Back to
Seekers of Perl Wisdom