Go Premium for a chance to win a PS4. Enter to Win


how cursor use global temporary table?

Posted on 2008-10-08
Medium Priority
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

cursor my_cur is
select *
from my_temp_table;


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

open my_cur for loop ....


Question by:luoora
  • 4
  • 2
LVL 74

Expert Comment

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.

Author Comment

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,
LVL 74

Expert Comment

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

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,
LVL 74

Accepted Solution

sdstuber earned 500 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.
LVL 74

Expert Comment

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.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

927 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