Global Temporary Taable

  • Permalink
  • submit to reddit
  • Email
  • Follow


I am using a global temporary table with "on commit preserve rows" in
order to pass a ref cursor back to the calling program.  The data is
returning fine.  However, I want to drop the table after the cursor is
returned.  If I insert a drop table statment inside of the procedure I
am getting the following error:

ORA-14452: attempt to create, alter or drop an index on temporary
table already in use.  If I close the session and go through TOAD I
can see the table but still can't drop it.  I get the same error.

I've researched via the internet and understand in a perfect
environment a "real" table is the way to go.  However, receiving
strong pushback from the customer.

Thanks For your help
0
Reply neil2391 (1) 6/25/2004 5:47:08 PM

See related articles to this posting

On 25 Jun 2004 10:47:08 -0700, neil@blueslate.net (Neil) wrote:

>I've researched via the internet and understand in a perfect
>environment a "real" table is the way to go

In a 'perfect' environment you don't need permanent temporary tables.
Fix your database design and/or your queries.


--
Sybrand Bakker, Senior Oracle DBA
0
Reply gooiditweg2 (295) 6/25/2004 6:30:17 PM

Neil wrote:

> However, I want to drop the table after the cursor is
> returned.

Please explain WHY you want to DROP the table.  

If I understand Oracle's intent properly, GTTs are intended to have a
permanent definition, supplied by the DBA ideally ONCE in the life of the
database).  The term TEMP is relative to the data, not the definition.

Without understanding your requirements, to me it appears that your design
is fundementally in conflict with the intent and implementation of temp
tables.

/Hans
0
Reply forbrich (430) 6/25/2004 6:46:51 PM

Neil wrote:
> 
> I am using a global temporary table with "on commit preserve rows" in
> order to pass a ref cursor back to the calling program.  The data is
> returning fine.  However, I want to drop the table after the cursor is
> returned.  If I insert a drop table statment inside of the procedure I
> am getting the following error:
> 
> ORA-14452: attempt to create, alter or drop an index on temporary
> table already in use.  If I close the session and go through TOAD I
> can see the table but still can't drop it.  I get the same error.
> 
> I've researched via the internet and understand in a perfect
> environment a "real" table is the way to go.  However, receiving
> strong pushback from the customer.
> 
> Thanks For your help

The term "global temporary table" is used because 

a) the table is permanently defined (hence the term "temporary")
b) the data is local to your session (hence the term "local")

:-)

Seriously though, a couple of things 

i) you don't need a temp table to pass a ref cursor around.  ref cursor
point to a resultset which does not need to "exist" as a temporary table

ii) if you are heading down the gtt route - you just populate it, use
the data, and then forget about the data.  It vanishes as soon as you
exit the session.  

hth
connor

-- 
Connor McDonald
Co-author: "Mastering Oracle PL/SQL - Practical Solutions"
ISBN: 1590592174

web: http://www.oracledba.co.uk
web: http://www.oaktable.net
email: connor_mcdonald@yahoo.com

Coming Soon! "Oracle Insight - Tales of the OakTable"

"GIVE a man a fish and he will eat for a day. But TEACH him how to fish,
and...he will sit in a boat and drink beer all day"

------------------------------------------------------------
0
Reply connor_mcdonald (351) 6/26/2004 2:30:56 AM

On 25 Jun 2004, neil@blueslate.net wrote:
> I am using a global temporary table with "on commit preserve
> rows" in order to pass a ref cursor back to the calling
> program.  The data is returning fine.  However, I want to drop
> the table after the cursor is returned.  If I insert a drop
> table statment inside of the procedure I am getting the
> following error:
> 
> ORA-14452: attempt to create, alter or drop an index on
> temporary table already in use.  If I close the session and go
> through TOAD I can see the table but still can't drop it.  I
> get the same error.
> 
> I've researched via the internet and understand in a perfect
> environment a "real" table is the way to go.  However,
> receiving strong pushback from the customer.

Just stop dropping the table.  Leave it there.  GTTs are used for
session-based data but they aren't to be constantly dropped.
They are tables, but their data is temporary.

If you have a connection pool, then you will need to clear it out
every call.

-- 
Galen Boyer
0
Reply galenboyer (300) 6/26/2004 4:17:04 AM
comp.databases.oracle.server 21363 articles. 10 followers. Post

4 Replies
119 Views

Similar Articles

[PageSpeed] 12

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Global Temporary Table
Hello Oraclegurus, I would like to know if i am doing the right thing or not?? I've created a global temporary table "tempcomp". "create global temporary table tempcomp (col1 number,col2 char,col3varchar2)" . I looked into these groups and it was mentioned somewhere that default is "on commit delete rows"... I am assuming that the rows are being deleted after commit and not stored . We have a web application which would be calling a stored procedure which inserts into a global temporary some values we nee...

Global Temporary Tables
Each, Am wanting to create a temporary table within a PLSQL package. Have used EXECUTE IMMEDIATE 'create global temporary table temp_status........' Problem now is that package wont compile due to insert statements for this table. Compiler has no idea about this temp table or its structure. I take it temporary tables arent designed for this use are am i missing something here? Cheers Roy Munson wrote: > Each, > > Am wanting to create a temporary table within a PLSQL package. Have > used > > EXECUTE IMMEDIATE 'create global temporary table temp_status.........

Global temporary table
Hi all! I dont know how to declare and use a global temporary table in my java stored procedure.... I used these statements: sql="declare global temporary table session.temp(recordinteger,eventtype character(20)) not logged"; Statement st=con.createStatement(); st.execute(sql); For inserting I'm trying to do.. sql="insert into session.temp values(2003,'fatal error'); st.executeUpdate(sql); But its flagging an error.With just the declare statement there is no error.But i read somewhere that a temporary table space needs to be created.I dont kn...

global temporary tables?
In our application we have a table that tracks network sessions. The usage is: 1) create a session record 2) read/update the record several times during the session 3) delete the session record when the session ends Update activity on this table is going to be pretty intense, and the transient nature of the data makes it a good candidate for a temporary and/or in-memory table. Unfortunately, different network connections may be updating the same session record at different times (connection pool), so the CREATE TABLE TEMPORARY doesn't seem to fit the bill, since i...

Global Temporary Tables
Hi, I am inserting records to a global temporary table(say A) in which a trigger is fired and im getting results from other global tempory tables(say B, C, D,..)... This is my scenario... I am able to fetch the results from the global temporary tables B,C,D,...when inserting directly in the table A from the front end. But I am not able to fetch the results from the global temporary tables B,C,D,...when inserting thru a web service (in dotnet)in the table A from the front end. Can somebody explain the reson for the above and give a solution to fetch the records from the global ...

Global temporary table and SP
Hello all, I'm using SS2K on W2K. Brieffing: Many months ago, I created a stored procedure only used by those with admin rights in SS. Now, someone else (without admin rights) has to run it. I gave him rigth to execute the SP but, at the second and more execution, he got a error message concerning a temp table already existing (see further). The SP: ------------------------------------------------------ CREATE PROCEDURE MySP @Type INT DECLARE @strSQL AS VARCHAR(4000) IF EXISTS (SELECT table_name FROM tempdb.information_Schema.tables WHERE table_name = '##MyTmpTable&#...

Global Temporary Table #2
Hello, We are running on Oracle 8.1.7.4 on Unix (AIX 4.3.3.0) I'm facing a problem with a global temporary table (on commit preserve rows) : it is going through the loop : - delete all - insert - update At the beginning of the procedure everything is going fine. I can see how the process is going on in v$session. After half an hour, the speed begins to decrease a lot and there are lot of "db file scattered read" events pointing to my temporary table. It is true that there are lots of FTS on this temporary table, but its content is very small (about 20 rows at each step of t...

Load global temporary table
Hi all, I have a fixedwidth .DAT file and a DB2 table, I have to create a flat file by pulling data from both file and DB2 table. I tried using IMPORT/LOAD utilities to load to a global temporary table and thought of joining it and extracting, but IMPORT/LOAD are not allowed on temporary table. Can you please suggest me how to go about it... thanks in advance, kore Can you Import it to a real TABLE, and then export with a join? B. As per my requirements I am not supposed to use a real table. Please suggest me..... vijay_dwi@yahoo.com wrote: > As per my requ...

EXPLAIN and Global Temporary Tables
I have my developers explaining the stored procedures that they write using visual studio. These stored procedures are for DB2 os390. In one case, one of the developers has defined a global temporary table that he uses to put the input parms into and then uses it to join against to create a dataset. When he runs explain (both visual explain, and CA's explain) it chokes on the SESSION.TABLE saying that it doesn't exist. Is there anyway I can have them explain these when they have global temporary tables defined? ...