Solved

Creating temporary tables within pl/sql

Posted on 2002-05-08
6
265 Views
Last Modified: 2010-04-17
I need to wirte a procedure in which i create temp tables and insert values in it from a select statement.
What would be the best way to do it?

Appreciate your help
0
Comment
Question by:NShaikh
  • 4
6 Comments
 
LVL 6

Expert Comment

by:Triskelion
ID: 6996804
Investigate
   CREATE CURSOR
0
 
LVL 47

Accepted Solution

by:
schwertner earned 100 total points
ID: 7002935
In addition to permanent tables, you can create temporary tables to hold session-private
data that exists only for the duration of a transaction or session.
The CREATE GLOBAL TEMPORARY TABLE command creates a temporary table
that can be transaction-specific or session-specific. For transaction-specific temporary
tables, data exists for the duration of the transaction, while for session-specific
temporary tables, data exists for the duration of the session. Data in a session is private
to the session. Each session can only see and modify its own data. DML locks are not
acquired on the data of the temporary tables. The clauses that control the duration of
the rows are:
• ON COMMIT DELETE ROWS to specify that rows are only visible within the
transaction
• ON COMMIT PRESERVE ROWS to specify that rows are visible for the entire
session
You can create indexes, views, and triggers on temporary tables and you can also use
the Export and Import utilities to export and import the definition of a temporary table.
However, no data is exported, even if you use the ROWS option. The definition of a
temporary table is visible to all sessions.
0
 
LVL 47

Expert Comment

by:schwertner
ID: 7002938
rem -------------------------------------------------------
rem Purpose:    Demonstrate Oracle 8i temporary tables
rem -------------------------------------------------------

drop table x
/

create global temporary table x (a date)
        on commit delete rows     -- Delete rows after commit
        -- on commit preserve rows   -- Delete rows after exit session
/

select table_name, temporary, duration
from   user_tables
where  table_name = 'X'
/

insert into x values (sysdate);

select * from x;

commit;
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 47

Expert Comment

by:schwertner
ID: 7002939
-- Inserted rows are missing after commit
select * from x;
0
 
LVL 47

Expert Comment

by:schwertner
ID: 7002987
So finaly a proposal looks like:

CREATE GLOBAL TEMPORARY TABLE  x
ON COMMIT PRESERVE ROWS
AS SELECT * FROM your_table;

0
 

Author Comment

by:NShaikh
ID: 7005161
This is the perfect answer.I will create a global temporary table and insert data in it  from a procedure and rows will be deleted on commit.

Thank you so much
Nisa

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Batch file output 20 78
count7 challenge 12 70
noX challenge 17 77
topping3 challenge 14 51
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

18 Experts available now in Live!

Get 1:1 Help Now