http://www.perlmonks.org?node_id=122716

randomblue has asked for the wisdom of the Perl Monks concerning the following question:

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.