http://qs321.pair.com?node_id=837462

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

Hi monks the following is the error that i am getting when running the following script

############################################ # Function: ############################################ #Print deleting line details to file and Continue sub outputdeletedlines { print $JBM " inside outputdeletedlines\n"; my $ai_div = $_[0]; my $ai_store = $_[1]; my $ai_reg = $_[2]; my $al_trans = $_[3]; #my $adt_h_date = $_[4]; my $org_adt_h_date = $_[4]; # print $JBM "-- $adt_h_date --"; my $adt_h_date = "'".$org_adt_h_date."'"; #2010-04-26 14:07:09 my $datetime = localtime(); my $file = $inputfile; my $delete_log = ''; my $ac_seq_nbr; my $ac_sale_amount; #If already has input files, outputs name of current working f +ile #Else puts a default one in the current directory if( $inputfile ) { $delete_log = $file . "_delete_" . $master_job_no . "- +" . $job_number . "\.log"; } else{ $file = 'Default'; $delete_log = $file . "_delete_0-0\.log"; } if( !$Config{delete_dir} ) { $Config{delete_dir} = getcwd(). "/"; } open( my $delete_fh, ">>", $Config{delete_dir} . $delete_log ) or die "Failed to open delete file\n"; my $SQL = "Select tran_seq_nbr, sale_amount From KCPOS_Tran_Header Where org_number = :org_no And store_number = :str_no And tran_number = :tran_no And terminal_number = :term_no And tran_Date = to_date(:tran_dt,'YYYY-MM-DD HH24:MI:SS')"; # And tran_Date = :tran_dt"; print $JBM "preparing delete SQL\n"; my $sth = $dbh->prepare($SQL) or die "Couldn't prepare statement: " . $dbh->errstr; # my $adt_h_date = $dbh->quote('$org_adt_h_date'); print $JBM "-- $adt_h_date --"; print $JBM "prepared SQL\n"; # $sth->execute(q{to_date('$adt_h_date','YYYY-MM-DD HH24:MI:SS +')}) # or die "Couldn't execute statement: " . $sth->errstr; $sth->bind_param(":org_no",$ai_div); $sth->bind_param(":str_no",$ai_store,); $sth->bind_param(":tran_no",$al_trans); $sth->bind_param(":term_no",$ai_reg); $sth->bind_param(":tran_dt",$adt_h_date); $sth->execute() or die "Couldn't execute statement: " . $sth->errstr; ( $ac_seq_nbr, $ac_sale_amount ) = $sth->fetchrow(); $sth->finish(); print $delete_fh "\n Tran_Seq_Nbr: $ac_seq_nbr\t Division: $ai +_div\t Store : $ai_store\t Register: $ai_reg\t Tran: $al_trans\t Date: $adt_h_date\t Sal +e Amt: $ac_sale_amount"; close $delete_fh; return; }

I know its because of $adt_h_date field which has the value like '2007-08-10 00:00:00'

so how should i overcome this error

error is: Placeholder :0 invalid, placeholders must be >= 1 at C:/Perl/lib/DBD/Oracle.pm l ine 273, <$data_fh> line 7.

thanks

Replies are listed 'Best First'.
Re: place holder error
by Corion (Patriarch) on Apr 29, 2010 at 07:31 UTC

    Most likely, somewhere in your large and unreadable SQL, you have :0, potentially because you're interpolating some variable, maybe $adt_h_date into your SQL. Don't interpolate your date field but pass it in as a placeholder as well.

Re: place holder error
by ww (Archbishop) on Apr 29, 2010 at 10:28 UTC
Re: place holder error
by apl (Monsignor) on Apr 29, 2010 at 10:14 UTC
    Have you printed out the SQL? Have you proven (rather than simply believing you know) which field has the :0 value?

    You may need to do some sanity-checking before you construct your query...

Re: place holder error
by ikegami (Patriarch) on Apr 29, 2010 at 15:28 UTC
    Like I said before, at the very least, this is wrong:
    my $adt_h_date = "'".$org_adt_h_date."'";
    It probably should be
    my $adt_h_date = $org_adt_h_date;