I have stored procedure returning me 7 resultsets, which I want to write to a .csv file using Perl. But for some reason(I do not know why) the .csv file only has the 1st set of resultset and all the other 6 sets are discarded. Is there a function in perl through which I can write all the 7 resultsets into the .csv file? Here is the part of the code that is doing it:
#!/cluster/uapp/perl/bin/perl -w use KAP ## A internally developed module with custom code to access th +e Database. use strict; use DBAccess; use DBD::CSV; my $db_lv_conn_file = "MSLV.eq_script_user"; my $read_dbi = undef; # Run stored proc my $sp = "lv..check_tax_lot"; ##This is the Stored Procedure that gives me back 7 Resultsets ### $read_dbi = KAP::opendbi($_db_lv_conn_file) || handle_error_and_ex +it ("Failed to get a connection to MSLV db server"); my $read_sth = $_read_dbi->prepare($sp); if($DBI::err) { handle_error_and_exit("**ERROR preparing $sp: " . $DBI::errstr +); } KAP::write_log("Prepare done, executing $sp"); $read_sth->execute(); if($DBI::err) { handle_error_and_exit( "**ERROR executing $sp: " . $DBI::errst +r); } KAP::write_log("Execute of $sp done"); my $datafile = "output.csv"; my $numrecords = 0; my @data = undef; # Loop through the data and write to file ##This is where I start to write into the .csv file## ##But it only writes the one resultset and discards the rest 6.## my $header_rec = join(",", @{$read_sth->{NAME}}); print $datafile $header_rec . "\n"; while (@data = $read_sth->fetchrow_array) { @data = EQ_Misc::arr_replace_undef("", @data); my $csv_record = join(",", @data); open (FH, ">>$datafile") or die "$!"; print FH "@data $csv_record .\n";; close $datafile; }
Any help will be appreciated.....

In reply to Writing Multiple Recordsets into a CSV file by sudip_dg77

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.