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

I am using DBI and DBD oracle under NT. The perl compiler I am using is ActiveState. I have trouble to using placeholder like ? mark as a place holder for input parameters. When I use it, the DBI interface will not work. in other words, it will not execute the SQL statement. Thanks you sheng

Replies are listed 'Best First'.
Re: DBI oracle
by btrott (Parson) on Mar 17, 2000 at 03:01 UTC
    Why don't you send a bit of your code?

    What exactly isn't working? Are you not getting any results, or are the prepare/execute methods failing?

    When you use the '?' placeholder, you don't need to quote your arguments--the placeholder handles the quoting for you. Perhaps this is the problem?

    use DBI; my $dbh = DBI->connect('foo', 'bar', 'baz', 'Oracle') or die "Can't connect: ", $DBI::errstr; my $sth = $dbh->prepare("select first_name from people where last_name + = ?") or die "Can't prepare: ", $dbh->errstr; my $last_name = "Bar"; $sth->execute($last_name); my $first_name; $sth->bind_columns(undef, \$first_name); while ($sth->fetch) { print $first_name, "\n"; }
Re: DBI oracle
by Anonymous Monk on Mar 17, 2000 at 21:07 UTC
    I suspect the place holder syntax you're using is incorrect.

    You need to use place holders of the form ":<whatever>"

            ### Prepare weeks in month cursor
            $weeks_in_mth_sth = 
                $dbh->prepare( qq {
               SELECT  count(*)
                 FROM  year_month_weeks
                 WHERE year_no = :year
                   AND month_no = :month
                              }
    
    Then you need to 'bind' the place holders to an actual variable as below :
    
        $weeks_in_mth_sth->bind_param(':year', $p_year);
        $weeks_in_mth_sth->bind_param(':month', $p_month);
    
    Then you should be able to execute your query :
    
        $weeks_in_mth_sth->execute
            or die "Can't execute SQL statement: $DBI::errstr Stopped\n";
    
    Good luck !