Ok, I think I understand you.

I wrote some code to process the CSV and the results were encouraging, 3 million records in about 5 minutes. However, I think a DBI connection to the database might be cleaner so this is what I have so far. You need to take A_ off the table names in the sql

#!perl use strict; use DBD::Oracle; use XML::Writer; use Data::Dump 'pp'; my $outfile = 'output.xml'; my $RLTP_ID = 10; # connect to database my $dbh = dbh(); # RLTP my $sql = 'SELECT rltp_id,rltp_name from A_RLTP_MNGR WHERE rltp_id=?'; my $sth = $dbh->prepare($sql); $sth->execute($RLTP_ID); my $RLTP = $sth->fetchall_hashref(1); # PRODUCT $sql = 'SELECT prod_id,prod_name from A_PRODUCT WHERE rltp_id=?'; $sth = $dbh->prepare($sql); $sth->execute($RLTP_ID); my $PRODUCT = $sth->fetchall_hashref(1); # CUSTOMER $sql = 'SELECT cust_id,cust_name from A_CUST WHERE rltp_id=?'; $sth = $dbh->prepare($sql); $sth->execute($RLTP_ID); my $CUST = $sth->fetchall_hashref(1); # ACCOUNT $sql = 'SELECT acc_id,acc_name,acc_balance from A_ACCOUNT WHERE rltp_id=?'; $sth = $dbh->prepare($sql); $sth->execute($RLTP_ID); my $ACCOUNT = $sth->fetchall_hashref(1); # TRANS my %TRANS=(); $sql = 'SELECT prod_id,cust_id,acc_id,txn_id,txn_amt from A_TRANSACTIO +N WHERE rltp_id=?'; $sth = $dbh->prepare($sql); $sth->execute($RLTP_ID); while (my @f = $sth->fetchrow_array){ $TRANS{$f[0]}{$f[1]}{$f[2]}{$f[3]}{'amt'}=$f[4]; } $dbh->disconnect; # CREATE XML my $t0 = time(); my $output = IO::File->new(">$outfile"); my $w = XML::Writer->new( OUTPUT => $output, DATA_MODE => 1, DATA_INDENT=>2 ); $w->startTag('transactiondetails'); $w->dataElement('rltp_id' => $RLTP_ID); $w->dataElement('rltp_name' => $RLTP->{$RLTP_ID}{'RLTP_NAME'}); for my $prod (sort keys %TRANS){ $w->startTag('product'); $w->dataElement('product_id' => $prod); $w->dataElement('product_name' => $PRODUCT->{$prod}{'PROD_NAME'}); for my $cust (sort keys %{$TRANS{$prod}}){ $w->startTag('customer'); $w->dataElement('cust_id' => $cust); $w->dataElement('cust_name' => $CUST->{$cust}{'CUST_NAME'}); for my $acc (sort keys %{$TRANS{$prod}{$cust}}){ $w->startTag('account'); $w->dataElement('acc_id' => $acc); $w->dataElement('acc_name' => $ACCOUNT->{$acc}{'ACC_NAME'}); $w->dataElement('acc_balance' => $ACCOUNT->{$acc}{'ACC_BALANCE'} +); #$w->dataElement('acc_type' => 0); $w->endTag('account'); } $w->endTag('customer'); } $w->endTag('product'); } $w->endTag('transactiondetails'); $w->end(); $output->close(); my $dur = time() - $t0; print "XML created as $outfile in $dur seconds\n"; # connect sub dbh { my $host = "localhost"; my $sid = 'xe'; my $user = 'user'; my $pwd = 'password'; my $dsn = "dbi:Oracle:host=$host;sid=$sid"; my $dbh = DBI->connect($dsn, $user, $pwd, { AutoCommit => 0, }) or die "$!"; return $dbh }

Let me know if I am on the right track and I will finish it off.

poj

In reply to Re^3: Convert CSV file to XML file using Perl? by poj
in thread Convert CSV file to XML file using Perl? by laknarc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.