Solved

convert a temp table in oracle to global temporary table

Posted on 2010-11-23
16
509 Views
Last Modified: 2013-12-07
Hi
I have a temp table created in my oracle package (version 11) that takes the date parameter and then I delete some tables in my schema based on those dates from temp table and also do a immediate insert records the same tables with new set of data, it is always fine in a single user session running the process but I find it is a problem when 2 users try use this process to run a request, the temp table does not work in  that scenario, how woulod I convert my temp table to global temp table, it is a oracle pacakge code with procedues and functions for insert and delete data.
0
Comment
Question by:mahjag
  • 6
  • 4
  • 3
  • +1
16 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 63 total points
ID: 34201477
simply drop your old table and then recreate it as a global temp with the same columns, triggers, contstraints, etc.

0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 62 total points
ID: 34201479
Take the create table syntax out of the pacakge and from a sql prompt add create gloobal temporary table syntax to it.

Then it's just like any other table.  Only choice is on commit to preserve rows or not.

Syntax is in the online docs.
0
 

Author Comment

by:mahjag
ID: 34201543
Thanks for the postings - does it work for multiple sessions of user accsessing same data - currently I get unique constraint error on a table that boith users tyring to insert same data, how is that will work for global temp table -  I want to understand genreally how gt table works on multi user application and each user can submit same request to delete and insert recrods to same table.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34201557
Yes.  Only the person inserting the data can see it.  When the session ends, the data is deleted.
0
 
LVL 14

Assisted Solution

by:ajexpert
ajexpert earned 125 total points
ID: 34201571
temp table is user and session specific.

We make use of global temporary table when the process populates and do some operations within same session.

Make sure you are aware of the global tempoary table concepts before you proceed
0
 

Author Comment

by:mahjag
ID: 34205400
hi alexpert

We make use of global temporary table when the process populates and do some operations within same session.

can you elaborate
0
 
LVL 14

Assisted Solution

by:ajexpert
ajexpert earned 125 total points
ID: 34206029
You can make use of global temporaray table within same session for the logged on user.

But you cannot make use of global temporaty table when

 "2 users try use this process to run a request, the temp table does not work in  that scenario"

HTH
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34213102
2 uses can use a  global temp table at the same time
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:mahjag
ID: 34214870
Hi Akexpert - I awarded points for the response - I wanted to find more details as to why we cannot use gloabl temp table for above case - I want to understand what I can use so that one process cannot insert the data without delete happen to the same session or diff session by actually locking the transaction - let me know..
0
 

Author Comment

by:mahjag
ID: 34214873
how to control transaction of not deleting one user session data with another?
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 34215232
This is separate question.  You may ask new question.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34215239
Might be seperate but close enough.

You don't need to delete from a GTT.  Once the session ends, Oracle does it for you.

I suggest the online docs for how they work.
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 34233632
Hi Sean,

Could you please explain with example?

"2 uses can use a  global temp table at the same time"

Since 2 users will have separate sessions how is it possible?

0
 
LVL 14

Expert Comment

by:ajexpert
ID: 34233639
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34233700
"Since 2 users will have separate sessions how is it possible?"

That's exactly how it's possible.

each session has its own version of the table.

If you and I are both logged in to the same database we can both insert/update/delete/select from our own temp table.  We can't share data from our respective temp tables, but that's the whole point.  We each get our own private workspace that lasts only for the duration of our session or transaction if configured to "ON COMMIT DELETE ROWS" instead of PRESERVE ROWS
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 34233732


Yes Sean, I concur with you.

I some how got confused and thought your reply may be pointing to sharing of data between two users in GTT

Thanks Sean
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to recover a database from a user managed backup
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now