Solved

how cursor use global temporary table?

Posted on 2008-10-08
6
3,515 Views
Last Modified: 2013-12-07
I am trying to create a global temporary table and cursor can use that. Since temporary
table not exist yet, got an compile error saying table my_temp_table not
exist. (see pseudo code) below. is there any way to get around or should I
take a different approach like using collection? thanks,
//
create or replace procedure test
is

cursor my_cur is
select *
from my_temp_table;

begin

execute immediate 'create global temporary table my_temp_table as .....";

open my_cur for loop ....

end;
//

thanks,
_______
0
Comment
Question by:luoora
  • 4
  • 2
6 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 22670549
create the global temporary table first (now) and then write your procedure.

No need to have the procedure create the table for itself.
That's the whole point of the GTT's  they can pre-exist and take no space or other resources until you actually need to use them.
0
 

Author Comment

by:luoora
ID: 22670619
can you please be a little bit more specific?

only this procedure need to use this temporary table. also other user (not me) will call this procedure so somehow they need to bundle together. thanks,
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 22670806
create the table in the same schema as the procedure owner.

the contents of a global temporary table are only visible to the session that populated it.
That's the whole point of them.

By any chance, are you trying to translate sql server code to oracle?
temporary tables in sql server are completely different than in oracle.

In oracle you create it once, and then simply reuse it.
In sql server you create and destroy them all the 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:luoora
ID: 22670980
thanks for your reply.

I understands your comments on global temporary table are only visible to the session that populated it. create the GTT myself won't work since I don't which box user will run my procedure or I don't want to recreate it every time after db restart.

by the way, I am not translating sql server code to oracle. thanks,
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 250 total points
ID: 22671007
you have to know which box your procedure will run on.  It's a procedure, so it runs inside the database.  create the table in that same database.  You won't have to recreate it after db restart.
You create it once and it's done.  

If you won't be doing the install into the database yourself.  Then simply put the create table and the create procedure statements into the same install script.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 22724319
why a c?  If you needed more help, you only needed to ask.  Please don't assign penalties without giving the volunteers (not just me) a chance.
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to take different types of Oracle backups using RMAN.

821 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