alex.TT2 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I continue to receive the following error when trying to execute the code below. The procedure is to convert a date using the SQL to_date function, return it to Perl for processing, and then feed the date into a stored SQL procedure. I've tried passing the date multiple ways but continue to get the same error. Please note that I receive the error with or without the exception handling (not too sure that exception part will work either).

Any insight you can provide would be greatly appreciated. Thank you.

Error Received:
Placeholder :0 invalid, placeholders must be >= 1 at C:/Perl64/lib/DBD/Oracle.pm line 321.

Code Used:
#!/usr/bin/perl use DBI; use strict; my $tdate = $ARGV[0]; my $dbh=DBI->connect("dbi:Oracle:dbname",username,password,{RaiseError + => 1 , PrintError => 0}); my $x; open ($x, '>P_RUN_TIME_LOG.txt'); my $sqlstmt = "select to_date('$tdate','mm/dd/yyyy') from dual"; my $sth = $dbh->prepare($sqlstmt); $sth->execute() or die $dbh->errstr; my $tmp; $sth->bind_columns(undef, \$tmp); while($sth->fetch()) {$tdate = $tmp;} # LOOP THROUGH RESULTS $t = localtime(); print $x "DATE formatted at $t. Formatted DATE is $tdate.\n\n"; $t = localtime(); print $x "Executing FT_PROC at $t.\n\n"; $sqlstmt = "BEGIN FT_PROC($tdate); EXCEPTION WHEN others THEN sql_stmt := 'INSERT INTO P_LOG (PRCDR, FT_DATE, RUN_ST +ATUS) VALUES ('FT_PROC', $tdate, 1)'; execute immediate sql_stmt; END;"; $sth = $dbh->do($sqlstmt) or die $dbh->errstr; $dbh -> disconnect;
  • Comment on Placeholder Error (Placeholder :0 invalid, placeholders must be >= 1)
  • Download Code

Replies are listed 'Best First'.
Re: Placeholder Error (Placeholder :0 invalid, placeholders must be >= 1)
by PeterPeiGuo (Hermit) on Jan 14, 2011 at 01:47 UTC

    If the only reason to select that date back is to use it later in the insert statement, then you really don't need to do that. If the type of FT_DATE column is Date, you can simply use to_date in the values clause of that insert statement.

    Peter (Guo) Pei

Re: Placeholder Error (Placeholder :0 invalid, placeholders must be >= 1)
by Anonyrnous Monk (Hermit) on Jan 14, 2011 at 07:13 UTC

    Presumably, you have a ":0" in your interpolated $tdate (resulting from something like 01/14/2011 00:00:00) which is being interpreted as an enumerated/named placeholder by DBD::Oracle.

    So, don't interpolate the date into your procedure, but use a placeholder (e.g. ->bind_param(':DATE' => $tdate)) in the first place.

Re: Placeholder Error (Placeholder :0 invalid, placeholders must be >= 1)
by runrig (Abbot) on Jan 14, 2011 at 17:01 UTC
    This doesn't look right:
    my $sqlstmt = "select to_date('$tdate','mm/dd/yyyy') from dual"; my $sth = $dbh->prepare($sqlstmt); $sth->execute() or die $dbh->errstr; my $tmp; $sth->bind_columns(undef, \$tmp); while($sth->fetch()) {$tdate = $tmp;}
    bind_columns binds columns to a list of variables. You're selecting one "column", and binding it to two "variables" (the first one is undef).

    undef is probably getting translated to placeholder number zero(oops, I'm confusing myself w/bind_col vs bind_columns...but the following still holds), you want:

    $sth->bind_col(1, \$tmp);
    Read the docs, bind_col and bind_columns are slightly different, and bind_col values start at 1, not 0.