Code:
my %tables;
while(<DATA>){
chomp;
my @tmp=split(",",$_);
if ($tmp[2] eq "VARCHAR2"){
$tables{$tmp[0]}->{$tmp[1]}->{val}=$tmp[2]." (".$tmp[3].")";
$tables{$tmp[0]}->{$tmp[1]}->{seq}=$.;
}
elsif($tmp[2] eq "NUMBER"){
$tables{$tmp[0]}->{$tmp[1]}->{val}=$tmp[2]." (".$tmp[3].",".$tmp[4].")";
$tables{$tmp[0]}->{$tmp[1]}->{seq}=$.;
}
else{
$tables{$tmp[0]}->{$tmp[1]}->{val}=$tmp[2];
$tables{$tmp[0]}->{$tmp[1]}->{seq}=$.;
}
}
for my $key (keys %tables){
print "CREATE TABLE ",$key,"(\n";
for my $k (sort {$tables{$key}->{$a}->{seq} <=> $tables{$key}->{$b}->{seq}} keys %{$tables{$key}}){
print $k," ",$tables{$key}->{$k}->{val},",\n";
}
print ");\n\n";
}
__DATA__
TEST1,fld1,VARCHAR2,3,,,
TEST1,fld2,DATE,,,,
TEST1,fld3,VARCHAR2,51,,,
TEST1,fld4,VARCHAR2,2,,,
TEST1,fld5,NUMBER,4,0,,
TEST1,fld6,VARCHAR2,1,,,
TEST1,fld7,TIMESTAMP,,,NOT NULL,
TEST1,fld8,VARCHAR2,16,,NOT NULL,1
TEST2,COLUMN1,VARCHAR2,100,,,
TEST2,COLUMN2,VARCHAR2,16,,NOT NULL,1
TEST2,COLUMN3,DATE,,,,
TEST2,COLUMN4,VARCHAR2,30,,,
TEST2,COLUMN5,VARCHAR2,30,,,
TEST2,COLUMN6,NUMBER,17,2,,
TEST2,COLUMN7,VARCHAR2,15,,NOT NULL,2
TEST3,COLUMN1,TIMESTAMP,,,NOT NULL,1