Opa mais infos.
Achei um codigo so que em php, mas nada complicado para passar ou estudar para perl.
E com certeza um codigo eh melhor que um module com dependencia como a acima hehe.
Ele converte de access para mysql, sendo assim pode ser que seja mais facil transferir de mysql para oracle.
<?php
/*
This script was written by Jason Farrell on this 4th day of April in 2003.
This code is solely for educational purposes and may not be redistributed
without the consent of the author. Any uses and/or responsibilites, outside
the permission of the author are not binding to the author in any way.
Please email comments to jfarrell@stu.wccnet.edu
*/
$odbc=odbc_connect('my_dsn','my_uname','my_pass'); //Open Connection to Datasource
$mysql=mysql_connect('my_host','my_uname','my_pass'); //Open Connection to MySQL and Select DB
mysql_select_db('my_db',$mysql);
$tablelist=odbc_tables($odbc); //This will create a result set of the available tables for the datasource
while (odbc_fetch_into($tablelist,$r)) //This will fetch each row into a hash $r
{
if (strtolower($r[3])=='table') //This is a regular table and is not tabular information
{
$q="select * from {$r[2]}";
$odbcset=odbc_exec($odbc,$q);
//Begin build sql insert command
while (odbc_fetch_into($odbcset,$row)) //Create a hash $row from the query to select all the data from the listed table
{
$c="insert into {$r[2]}(".odbc_field_name($odbcset,1); //Build Intial Insert Statement for data insertion into mysql
for ($i=2; $i<=odbc_num_fields($odbcset); $i++) //Loop in remainder of field names
{
$c .= ",".odbc_field_name($odbcset,$i);
}
if (is_numeric($row[0])) { //Build Initial Value parameters values
$c.=") values(".$row[0];
} else {
$c.=") values('".$row[0]."'";
}
for ($i=1; $i<count($row); $i++) //Loop in remainder
{
if (is_numeric($row[$i])) {
$c .= ",".$row[$i];
} else {
$c .= ",'".$row[$i]."'";
}
}
$c.=")";
#echo $c."<br>\n";
if (mysql_query($c,$mysql)) { //Insert the Data into the table
echo "Success<br>\n"; //Echo Success if it worked
} else {
die(mysql_error()); //IF it fails die
}
}
}
}
mysql_close($mysql); //Close all open connections
odbc_close($odbc);
?>
</body>
</html>
Opa mais um codigo, agora de mysql para oracle.
#!/usr/bin/perl -w
use strict;
use vars qw/$DEBUG %output %types $filename $outfile $loading/;
use Getopt::Long;
$DEBUG = 0;
%output = ();
%types = ();
GetOptions('infile=s' =>\$filename,
'outfile=s'=>\$outfile,
'load'=>\$loading);
defined $filename or die "MySQL Ensemble table file not given...\n";
defined $outfile or $outfile = "oratable.sql";
open(SQL, "<$filename");
while (<SQL>) {
chomp;
/^ *\#/ and next;
# bugger, synonym is not a valid oracle column name
/create table/i and parseCreateTable(\*SQL ,$_);
}
buildSchema();
sub buildSchema {
open (SCHEMA, ">$outfile");
open (CONSTRAINTS, ">$outfile.con") if defined $loading;
while (my ($table, $rh_definition) = each %output) {
print SCHEMA "\nCREATE TABLE ", $table, " (";
my $columnDefinition = " ";
foreach my $column (@{$rh_definition->{'columns'}}) {
$columnDefinition .= "\n\t" . $column . ",";
}
# last , needs removing
$columnDefinition =~ s|,$|\n\);\n|;
print SCHEMA $columnDefinition;
#output the primary key data
defined $output{$table}->{'primarykey'} and do {
my $out = "\nalter table " . $table . " add constraint " . $table . "_pk ". $output{$table}->{'primarykey'} . ";\n";
defined $loading ? print CONSTRAINTS $out : print SCHEMA $out;
};
# output the normal key data
defined $output{$table}->{'key'} and do {
foreach my $rl_key (@{$output{$table}->{'key'}}) {
my $out = "\ncreate index " . $rl_key->[0] . " on " . $table . " " . $rl_key->[1] . ";\n";
defined $loading ? print CONSTRAINTS $out : print SCHEMA $out;
}
};
defined $output{$table}->{'unique'} and do {
foreach my $rl_unique (@{$output{$table}->{'unique'}}) {
my $out = "\ncreate unique index " . $rl_unique->[0] . " on " . $table . " " . $rl_unique->[1] . ";\n";
defined $loading ? print CONSTRAINTS $out : print SCHEMA $out;
}
};
}
}
sub parseCreateTable {
my ($fh, $firstLine) = @_;
my $tableName;
if ($firstLine =~ /(create table) +(\w+) *\(/i) {
$tableName = $2;
} else {
die "Line does not match create table: $firstLine";
}
while (<$fh>) {
chomp;
$_ =~ s/\s+//i;
$_ =~ s/synonym/synonymname /gi;
# return if it matches close bracket
/\);/ and return;
# there is a problem with the MAX_ROWS stuff. Look at it later
/\) *MAX_ROWS.+;/ and return;
# skip empty lines
next if /^ *$/;
next if /^ *\#/;
# process table keys and constraints
/primary key/i and do {parsePrimaryKey($tableName, $_); next};
/^ *key/i and do {parseKey($tableName, $_);next};
/unique/i and do {parseUniqueConstraint($tableName, $_); next};
parseColumnDefinition($tableName, $_);
}
}
sub parsePrimaryKey{
my ($table, $def) = @_;
$def =~ s/^ *//;
$def =~ s/, *?$//;
$DEBUG and print "\n--->DEBUG: $def\n";
$output{$table}->{'primarykey'} = $def;
}
sub parseKey {
my ($table, $def) = @_;
$def =~ s/^ *//;
$def =~ s/, *$//;
if ($def =~ /(KEY) +(\w+) *(\(.+\))/i) {
push @{$output{$table}->{'key'}}, [$table . $2, $3];
} elsif ($def =~ /(KEY) *(\(.+\))/i) {
my $index = 1;
$index = scalar @{$output{$table}->{'key'}} + 1 if
defined $output{$table}->{'key'};
push @{$output{$table}->{'key'}}, [$table . "_key_" . $index, $2];
} else {
die "Unknown key definition: ", $def;
}
}
sub parseUniqueConstraint{
my ($table, $def) = @_;
$def =~ s/^ *//;
$def =~ s/, *$//;
my $index = 1;
if ($def =~ /UNIQUE KEY (.*?) *(\(.+?\))/i) {
push @{$output{$table}->{'unique'}}, [$table.$1, $2];
} elsif ($def =~ /UNIQUE +(.*?) *(\(.+?\))/i) {
push @{$output{$table}->{'unique'}}, [$table.$1, $2];
} elsif ($def =~ /UNIQUE *(\(.+?\))/i) {
push @{$output{$table}->{'unique'}}, [$table . "_" . $index, $1];
} else {
die "unique constraint doesn\'t parse: ", $def;
}
}
sub parseColumnDefinition {
my ($table, $def) = @_;
# throw out , if it is in there
$def =~ s/,\s*$//;
$def =~ s/^ +//;
my $columnName = "";
# get column name
$def =~ /^([^ ]+)/ and $columnName = $1;
#convert typedefinitions
$def =~ s/mediumtext/clob/gi;
$def =~ s/int\([0-9]*\)/number/gi;
$def =~ s/integer\(.*\)/number/gi;
$def =~ s/INT /number /gi;
$def =~ s/double\(.*\)/number/gi;
$def =~ s/tinynumber/number/gi;
$def =~ s/bignumber/number/gi;
$def =~ s/varchar/varchar2/gi;
$def =~ s/datetime/date/gi;
$def =~ s/ time /varchar2(40)/gg;
$def =~ s/auto_increment//gi; # this can lead to bugs
$def =~ s/unsigned//gi;
$def =~ s/^start /start_point /gi;
$def =~ s/^end /end_point /gi;
#this is an interesting one; replace enum with check (value in
$def =~ s/enum *(\(.*\))(.*)/varchar2(20) $2 CHECK \($columnName IN $1\)/i;
# there is a nasty problem with the time things; this is a way to solve it
# but is probably not correct....
$def =~ s/\'0000-00-00 00\:00\:00\'/to_date\( \'01-01-0001\', 'dd-MM-yyyy' \)/;
$DEBUG and print "--->DEBUG: $def\n";
push @{$output{$table}->{'columns'}}, $def;
}