Re: Question about bind_param and Oracle

From: David N Murray (dmurray_at_jsbsystems.com)
Date: 07/16/04


Date: Fri, 16 Jul 2004 11:57:05 -0400 (EDT)
To: alsalvo@sherwin.com

You can't use a parameter for the table name. You have to use dynamic sql
(i.e. put it in the $sql var before the prepare). There's no point in the
prepare if the DB can't even figure out what table is going to be hit.

This should be a FAQ, but I didn't see it in there.

hth,
dave

On Jul 16, alsalvo@sherwin.com scribed:

> Hi all,
>
> Hoping someone can help me out here.
>
> I'm trying to do the following using Oracle 9i and DBI:
>
> $table_name = "USERS";
>
> $sql = "SELECT COUNT(*) FROM ?";
>
> $sth = $dbh->prepare($sql);
>
> $sth->bind_param(1,$table_name);
>
> $sth->execute;
> .
> .
> .
> However, I'm getting an error about an invalid table name (I have verified
> that the table is valid and that I spelled it correctly).
>
> Is this even possible with Oracle and DBI?
>
> Please let me know.
>
> Thanks.
>
> Aaron Salvo



Relevant Pages

  • Re: Beginners question : How to use varchar2 within a sql statement ?
    ... in a Oracle 10g database. ... If I try to use the variable tablename in a select statement I get the ... The sql is also parsed at compile time. ... The opposite of static sql is dynamic sql. ...
    (comp.databases.oracle.misc)
  • Re: New to Oracle: DDL in EXECUTE IMMEDIATE question
    ... I'm new to Oracle. ... DDL from within an application every time I need the object... ... I am not an advocate of dynamic sql, ... quicker to create my objects using EXECUTE IMMEDIATE than not. ...
    (comp.databases.oracle.server)
  • Re: Accessing a cursor using dynamic SQL
    ... just do an equal join of the tables and then compare each field, ... It seems that I would use a cursor when ... executing this dynamic sql for the join, but I do not know how to ... Puget Sound Oracle Users Group ...
    (comp.databases.oracle.misc)
  • Re: Any expert Pro*C/C++ programmer out there?
    ... Ramon F Herrera wrote: ... I think that 'dynamic SQL' is what you are looking for. ... Oracle is quite explicit about that. ...
    (comp.databases.oracle.server)