Ready, Mike [mailto:[EMAIL PROTECTED] wrote:
> 
> Hi
> Is there a way to use a bind variable to pass a tablename into an oracle
> create table statement - e.g.
> CREATE TABLE ?
> (
>   CASE_NUM       NUMBER,
>   TLM_PROG       VARCHAR2(50 BYTE),
>   TLM_REASON     VARCHAR2(100 BYTE),
>   TLM_CREATE_DT  DATE,
>   TLM_TASK_NAME  VARCHAR2(50 BYTE),
>   TLM_ACTION     VARCHAR2(50 BYTE)
> )
> 
> where ? gets replaced with a bind variable holding a temp table name
> that contains the date?  I can do it by substituting the date into the
> sql string or by concatenating the tablename with a couple of strings to
> create the sql statement, but it seems cheesy.  If I try to do it using
> a bind variable, it errors out.

No.  Bind variables can only be used with DML (e.g. SELECT, INSERT), not
with DDL (e.g. CREATE, ALTER), and only in place of values, not in place of
object names.

I might write the code something like this:

my $table_name = 'tmp_' . $date;

my $create_sql = <<"EndOfSQL";
  CREATE TABLE $table_name
    (
     CASE_NUM    NUMBER,
     ...
    )
EndOfSQL

I'd probably put it in a subroutine that allowed the table name to be passed
in.

HTH,
Ronald


Reply via email to