I most often use SQLite.
I use $dbh (data base handle) instead of $conn.

First of all, you have to connect to the Database using the DBI module.

my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","",{RaiseError = +> 1}) or die "Couldn't connect to database: " . DBI->errstr;
If $dbh is zero undefined, then the connect failed!
If the connection works, then I've given some guidance about how to handle future errors.
Your connect syntax will be different for the Oracle database.

Next step is to prepare your SQL statement:

my $get_all_user_rows = $dbh->prepare ("SELECT * FROM users");
I use all CAPS for SQL keywords, but that is just my preference - doesn't matter.

Now you have to execute the prepared SQL statement:

$get_all_user_rows->execute();
Now you have to retrieve the data from that executed statement.
The easiest in this case, would be to ask for a reference to all of the rows.

my $all_row_ref = $get_all_user_rows->fetchall_arrayref;
Now print the data from this 2-D array:
foreach my $row_ref (@$all_row_ref) { print "@$row_ref\n"; }
There is more, a lot more to this than the basics I showed above.
I may have made a mistake which the other Monks will quickly point out.
I don't have your DB, but this is, I think a general "roadmap" to get a first result.

In reply to Re: Perl Not returning SQL query result by Marshall
in thread Perl Not returning SQL query result by santoo

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.