Re: Creating an oracle temp table with a variable table name
- From: Mladen Gogala <gogala@xxxxxxxxxxxxx>
- Date: Wed, 21 Jun 2006 14:52:57 GMT
Mike Ready 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.
Thanks
Mike R.
Michael P. Ready
Texas ACCESS Alliance
Work 512-533-3959, Mobile 512-796-7085, Fax 512-437-6532
AIM: michaelpready
mike.ready@xxxxxxxxxxxx
Mike, you misunderstood database binding process. Database can bind variables to a placeholder in statement that can be parsed. In order
to parse a SQL statement, database must know which objects are referred
to in the statement, what access privileges does the user have and which
access path will be used to access those objects. That means that there
can be no binding if the table name is not known in advance. What you
want is called "dynamic execution". You can always dynamically create
table like this
sub cr_tab {
my ($dbh,$table_name)=@_;
my $cr_table=qq( create table $table_name (
CASE_NUM NUMBER,
TLM_PROG VARCHAR2(50),
TLM_REASON VARCHAR2(100),
TLM_CREATE_DT DATE,
TLM_TASK_NAME VARCHAR2(50),
TLM_ACTION VARCHAR2(50)));
$dbh->do($cr_table);
}
--
Mladen Gogala
http://www.mgogala.com
.
- References:
- Creating an oracle temp table with a variable table name
- From: Mike Ready
- Creating an oracle temp table with a variable table name
- Prev by Date: RE: problem with subclassing DBI and " is not a DBI handle (has no magic)" error
- Next by Date: RFC: SQL::KeywordSearch 1.1
- Previous by thread: Re: Creating an oracle temp table with a variable table name
- Next by thread: RE: Creating an oracle temp table with a variable table name
- Index(es):
Relevant Pages
|