Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

how to use place holders?

by Anonymous Monk
on Aug 03, 2005 at 19:33 UTC ( #480614=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I tired to use place holders and i am getting following error :

ORA-01008: not all variables bound (DBD ERROR: error possibly near <*> + indicator
Here is my code:
use DBI; use DBD::Oracle qw(:ora_types); use DBD::ODBC; use Getopt::Long; main(); ########################################################### sub main { $dbh = DBI->connect("dbi:ODBC:$DSN"); $sqlstatement="SELECT * from test_table"; $dbh->{LongReadLen} = 140000; $sth = $dbh->prepare($sqlstatement); $sth->execute || DIE("Could not execute SQL statement ... maybe invalid?"); $row_access=0; while (@row=$sth->fetchrow_array) { $c1 = func("COL1",0,1); $c2 = func("COL2",1,2); $INSERT_SQL="INSERT INTO trg_table(". "column1,". "column2". ") VALUES ". "(?,". "?)"; $INSERT_CURSOR=$LDA_DB->prepare($INSERT_SQL); $rv = $INSERT_CURSOR->execute(); $INSERT_CURSOR->finish; $row_access++; } $INSERT_CURSOR->finish; $LDA_DB->disconnect; close(W); } ########################################################### sub func { # if there is no value it replaces with " " otherwise it replaces wi +th value. } ###########################################################
can any one help me with this? column1, column2 being target table columns and COL1, COL2 being source table columns.

while using place holders, what all things i need to take care of?

thanks.....

edit (broquaint): added formatting

Comment on how to use place holders?
Select or Download Code
Re: how to use place holders?
by gellyfish (Monsignor) on Aug 03, 2005 at 19:39 UTC

    If I can guess what it is what you are trying to do I think you want:

    $rv = $INSERT_CURSOR->execute($c1, $c2);
    - you pass the values for the placeholders to the execute

    /J\

Re: how to use place holders?
by Enlil (Parson) on Aug 03, 2005 at 19:42 UTC
    You need to pass some arguments to execute: That is:
    $INSERT_CURSOR->execute();
    Should be:
    $INSERT_CURSOR->execute($some_var,$some_other_var);
    As you have two place holders but in your $INSERT_CURSOR but no variables bound to them when you call execute it. Note that in the above the variables $some_var, and $some_other_var relate to the two ? in your statement. Have a look at: The DBI Documention on Placeholders

    -enlil

      Thank you! It worked! thanks......
Re: how to use place holders?
by Joost (Canon) on Aug 03, 2005 at 19:50 UTC
off-topic: using q() and qq() to improve readability
by Codon (Friar) on Aug 04, 2005 at 00:01 UTC

    Something you can do to make your code easier to read (beyond the formating in this forum) is to use q() and qq(). For example, where you do this:

    $INSERT_SQL="INSERT INTO trg_table(". "column1,". "column2". ") VALUES ". "(?,". "?)";
    Try this instead:
    $INSERT_SQL= q{ INSERT INTO trg_table( column1, column2 ) VALUES (?,?) };

    Because you do not need variable interpolation here, you can use single quotes. If you need to do variable interpolation, use qq() instead.

    Ivan Heffner
    Sr. Software Engineer, DAS Lead
    WhitePages.com, Inc.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://480614]
Approved by VSarkiss
Front-paged by astaines
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2014-12-28 01:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls