Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

convert a temp table in oracle to global temporary table

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
mahjag
Asked:
mahjag
  • 6
  • 4
  • 3
  • +1
4 Solutions
 
sdstuberCommented:
simply drop your old table and then recreate it as a global temp with the same columns, triggers, contstraints, etc.

0
 
slightwv (䄆 Netminder) Commented:
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
 
mahjagAuthor Commented:
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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
slightwv (䄆 Netminder) Commented:
Yes.  Only the person inserting the data can see it.  When the session ends, the data is deleted.
0
 
ajexpertCommented:
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
 
mahjagAuthor Commented:
hi alexpert

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

can you elaborate
0
 
ajexpertCommented:
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
 
sdstuberCommented:
2 uses can use a  global temp table at the same time
0
 
mahjagAuthor Commented:
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
 
mahjagAuthor Commented:
how to control transaction of not deleting one user session data with another?
0
 
ajexpertCommented:
This is separate question.  You may ask new question.
0
 
slightwv (䄆 Netminder) Commented:
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
 
ajexpertCommented:
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
 
ajexpertCommented:
0
 
sdstuberCommented:
"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
 
ajexpertCommented:


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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now