Good Morning. I was wondering if anyone had run into an issue with DBI, where, when you have mixed data types coming back, it would return a number such as 0301 as 301. I was wondering if anyone had found an easy fix for it so that it provides the entire number? I just posted the sub that I am using. It's an Oracle connection. Please let me know if anyone has any questions. thanks in advance! -theleftsock

UPDATE:

Thank you for the responses. After I retested several of my responses, it appears it is not an issue.

To Corion's point, They are VARCHAR2 in the database, and are coming back correct. The columns are of mixed data types, with this type of sub used in a couple different places. It's hard to tell the data type up front. I believe I had done some post processing on the files, and when I evaluated these in post-processing that is where it is evaluating 0301 as 301. I am updating my post processing to be more aware of leading 0's on integer values. I am using printf, sprintf in most cases there, I just need to be more cautious when I slurp the files.

Very much thanks for the responses!

sub run_select { #takes a dbh, a string of SQL my ($dbh_, $sql_) = @_; my ($result, $sth, $col_name_aref); print "in run_select sql_: $sql_\n"; if ($sql_ =~ /;/) { $sql_ =~ s/;//; } $sth = $dbh_->prepare($sql_); eval {$sth->execute;}; if ($@) { write_log($log_file, "error with execute in run_select in $0\n +"); write_log($log_file, "error: $@"); } else { $col_name_aref = $sth->{NAME}; $result = $sth->fetchall_arrayref; } return ($result, $col_name_aref); #returns an aref of the values a +nd an aref of the column names }

In reply to DBI Removing Leading Zeroes 0's by theleftsock

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.