I am trying to write followings.
Requirement: query "Employee" table for emp_id and first_name, for each returned emp_id, query customer table for customer_name where id=emp_id(from employee table).
but not getting expected output. Any problem with the code?
#!/home/y/bin/perl use DBI; use File::Basename; #Database handler my $dbh= DBI->connect("dbi:mysql:$conf{MSQL_DB}:$conf{MSQL_DB_HOST}:33 +06", "$conf{MSQL_DB_USER}" , "$conf{MSQL_DB_PSW}" , { RaiseError => 1 +, AutoCommit =>0} ) || die "Database Connection Failed: $DBI::errstr" + ; print "$conf{MSQL_DB} DB :Connection succeeded\n"; my $pr = qq{select emp_id, first_name from employee where city= "Atlan +ta" }; #stage prepare and execute my $sth = $dbh->prepare($pr); $sth->execute(); # bind sql columns $sth->bind_columns( undef, \$emp_id, \$first_name); while ($sth->fetch) { print "EMP_ID = $emp_id, FirstName=$first_name \n"; # Capture the quarantine_stage_id my $pr1 = qq{select customer_name from customer where id = $emp_id } +; # Prepare and Execute the SQL statement my $sth1 = $dbh->prepare($pr1); $sth1->execute(); $cust_id; $sth1->bind_columns( undef, \$cust_id ); while ($sth1->fetch) { print "Customer Table: Customer ID = $cust_id \n"; if ($emp_id == $cust_id) { print "\n Match\n"; } else {print "Doesn't Match"} } $sth1->finish(); } $sth->finish(); $dbh->disconnect();

In reply to how to use nested statement handler? by hardikv

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.