Hi Monks,
I am trying to create dynamic SQL <query.
First, I build a query with placeholders, something like:
my $query = "INSERT INTO $table_name (F1,F2,F3...) VALUES (?,?,?,...)" +;
And then I bind the values using the following code:
my $sth = $dbh->prepare($query); my @params = @$bind_params; my ($i,$j); for ($i = 0,$j=1; $i <= $#params;$i++,$j++){ $sth->bind_param($j,$params[$i]); } $sth->execute();
Now, I get the followong DBA error:
ORA-01858: a non-numeric character was found where a numeric was expec +ted (DBD ERROR: error possibly near <*> indicator at char 173 in 'INS +ERT INTO user_session (auth_id,expiry_date,remote_address,num_days,ve +rification,creation_date,login_id,inst_code,handle,last_update_date) +VALUES (:p1,:p2,:p3,:p4,:p5,:<*>p6,:p7,:p8,:p9,:p10)') [for Statement + "INSERT INTO user_session (auth_id,expiry_date,remote_address,num_da +ys,verification,creation_date,login_id,inst_code,handle,last_update_d +ate) VALUES (?,?,?,?,?,?,?,?,?,?)" with ParamValues: :p1="user1name", + :p10='sysdate', :p2='to_date('22-05-2011 23:59:59','DD-MM-YYYY HH24: +MI:SS')', :p3='il-pr01.corp.mygroup.com:8991/prs;10.1.116.190;', :p4= +0, :p5='fencpw('user1pass')',:p6='sysdate', :p7='user1name', :p8='USM +50', :p9="22520111126163902333386268343"]

It seems that there is a problem in using reserved words e.g. SYSDATE or TO_DATE.
The bind function treats them as a string.
Is there a way to solve this?
Thanks,
Asaf

In reply to DBI bind_param by asafp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.