I'm trying to write DBI code for Oracle 8.1.7 that uses placeholders. I've tried several variations that I have found on Perlmonks and elsewhere, but none of them work.

Here is what I'm trying to do:

use DBI; use DBD::Oracle; # Define sid, user, password, etc. here my $dbh = DBI->connect($DB_SID, $DB_USER, $DB_PASSWORD, 'Oracle') or die( $dbh->errstr ); my $name = "guppy"; my $sql_statement = 'SELECT foo FROM table_bar WHERE name = ?'; $sth = $dbh->prepare( $sql_statement ) or die( $dbh->errstr ); # This is where I try to replace the placeholder with $name $sth->execute( $name ) or die ( $dbh->errstr ); while( $aref = $sth->fetchrow_arrayref ) { print $aref->[0] ."\n"; } $sth->finish; $dbh->commit; $dbh->disconnect;

When I try to use placeholders, the script runs without any output or errors. The only place where placeholders have worked for me is inside the VALUES() brackets in an INSERT statement. Incidentally, hard-coded SQL statements work just fine. Am I doing something obviously silly? I am new to DBI, so that's quite possible.


In reply to DBI placeholders by randomblue

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.