PL/SQL to create a temp table that will be dropped after session ends

Is it possible in PL/SQL to create a temp table that will be dropped after the session ends? Please provide example if possible. I can create a global temp table in PL/SQL but I am not sure how (if possible) to have it 'drop' once the session ends.
DB: 10g
OS: Wiindoze 2003 Server
:-)

As others have mentioned (but probably not clearly explained), Oracle treats temporary tables differently to SQL Server.
In SQL Server you create a temporary table and it gets dropped (automatically I assume, I dont do SQL Server) after the session finishes. This will obviously allow each session to "request" a temporary table to use, then use it, and not have to worry about cleaning up the database after the session has finished.
Oracle takes a different approach...
On the assumption that each session is likely to be creating a temporary table for the same purposes, with the same structure, Oracle let's you create a Global Temporary Table a.k.a. GTT (which you've already come across). You only have to create this table once and you leave it on the database. This then means that any code written to use that table doesn't have to be dynamic code and can be verified and checked at compile time, just like code written for any other table. The difference of a GTT from a regular table is that any data you put into that table can only be seen by that session and will not interfere with any data of other sessions and, when you either commit, or end the session (depending on the "on commit delete rows" or "on commit preserve rows" option used when creating the GTT), that data from your own session will automatically be removed and hence the table is cleaned up that way, whilst the actual table itself remains.
Some people from SQL Server backgrounds try and create and drop tables dynamically in their PL/SQL code, but this leads to problems...
SQL> ed
Wrote file afiedt.buf
  1  begin
  2    execute immediate 'create table my_temp (x number)';
  3    insert into my_temp values (1);
  4    execute immediate 'drop table my_temp';
  5* end;
SQL> /
  insert into my_temp values (1);
ERROR at line 3:
ORA-06550: line 3, column 15:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 3, column 3:
PL/SQL: SQL Statement ignoredi.e. the code will not compile for direct DML statements trying to use that table.
They then try and get around this issue by making their DML statements dynamic too...
SQL> ed
Wrote file afiedt.buf
  1  create or replace procedure my_proc is
  2  begin
  3    execute immediate 'create table my_temp (x number)';
  4    execute immediate 'insert into my_temp values (''A'')';
  5    execute immediate 'drop table my_temp';
  6* end;
SQL> /
Procedure created.... which looks great and it compiles ok... but... when they try and run it...
SQL> exec my_proc;
BEGIN my_proc; END;
ERROR at line 1:
ORA-01722: invalid number
ORA-06512: at "SCOTT.MY_PROC", line 4
ORA-06512: at line 1... oops the code has a bug in it. Our DML statement was invalid.
This is really something that would have been caught at compile time, if the statement had been a direct DML statement rather than dynamic. And thus we see the problem with people trying to write all their code as dynamic SQL... it's more likely to contain bugs that won't be detected at compile time and only come to light at run time... sometimes only under certain conditions and sometimes once it's got into a production environment. Bad Idea!!!! ;)
Far better to never create tables (or most other database objects) at run time. Just create them once as part of the database design/implementation and use them as required, allowing you to catch the most common coding errors up front before they get anywhere near a test environment or worse still, a production environment.

Similar Messages

  • Can i create a duplicatable table that will respond to modifications?

    I generally create a table and copy and paste that table in several different sheets.  sometimes i need to add rows or columns.  Is there a way that when i add rows and columns to the table in the master sheet that it will automatically add them in the tables on the other sheets without having to go into each sheet and manually add them to each table?

    Hi Dalan,
    You can't increase the size of tables using a formula, but you can start with a set of oversize destination tables, and modify the formulas to return a specific result in event of an error (such as would be caused by cells in the 'extra' rows referencing non-existant cells in the main table.
    These rows could be automatically hidden until they had content in a specific column.
    Here's an example. The Main table is on the left, one of the 'satellites' is on the right.
    Here, no adjustent has been made for the rows of the satellite beyond the number of rows in the Main;
    extra rows throw error messages, indicated by the red triangles:
    Formulas: Main, column D:
    D2: =IF(LEN(A2&B2&C2)>0,1,"")
    Fill down.
    Sat 1:
    A1: =Main::A1
    Fill down, Fill right
    Below, the selected table is a copy of the first 'satellite' table. No change in the formulas. The only change is the addition of a Reorganize rule, shown below the table:
    As more rows are added to Main (and more rows of that table are filled with date), the satellite table(s) will 'grow', showing mirrors of all the rows on Main containing data:
    The growth will stop when the number of filled rows in Main exceeds the number of rows available in Sat 2.
    Late thought: As I was writing this, I realized that column D on Main is not necessary, and may be deleted. With a minor change to the formulas in columns A, B ad C, the calculatons can be as easily done on the satellite tables themselves, using the same formula in column D as was used above in column D of Main.
    Sat 1::A1: =IF(LEN(MAIN::A1)>0,MAIN::A1,"")
    Fill right to C1, Fill Down to last row of the table (Sat 1).
    Sat 1::D2: =IF(LEN(A2&B2&C2)>0,1,"")
    Fill down to end of table.
    Regards,
    Barry

  • Problem with SQL to create a temp table to evaluate sort merge join

    Can anyone help me with the below sql to enable the performance of the use merge join to be evaluated. This sql is placed in a file and ran from the prompt.
    timing start
    CREATE table testsql as
    SELECT /*+ USE_MERGE(t1000 t8000)*/ t1000, t8000
    FROM t1000, t8000
    WHERE t1000.ONEPERCENT=1 AND t1000.unique1 = t8000.fk;
    timing stop
    drop table testsql;
    Current error message:
    SQL> start h:\exe1.sql
    SELECT /*+ USE_MERGE(t1000 t8000)*/ t1000, t8000
    ERROR at line 2:
    ORA-00904: "T8000": invalid identifier
    Elapsed: 00:00:00.01
    drop table testsql
    ERROR at line 1:
    ORA-00942: table or view does not exist
    Thanks for your help,
    Regards, Chris.

    SELECT /*+ USE_MERGE(t1000 t8000)*/ t1000, t8000
    Are you sure you have columns t1000 and t8000 in one of your tables used in the from clause?
    What is the idea of this exercise? what is it that you are trying to evaluate?

  • How to create a temp table in the memory, not in disk?

    in sql server, you can create a temp table in the memory instead of disk,
    then you can do the insert, delete,update and select on it.
    after finishing, just release it.
    in Oracle,
    I am wonderfing how to create a temp table in the memory, not in disk?
    thanks,

    Thanks for rectifying me Howard.
    I just read your full article on this too and its very well explained here:
    http://www.dizwell.com/prod/node/357
    Few lines from your article
    It is true, of course, that since Version 8.0 Oracle has provided the ability to create a Keep Pool in the Buffer Cache, which certainly sounds like it can do the job... especially since that word 'keep' is used again. But a keep pool is merely a segregated part of the buffer cache, into which you direct blocks from particular tables (by creating them, or altering them, with the BUFFER POOL KEEP clause). So you can tuck the blocks from such tables out of the way, into their own part of the buffer cache... but that is not the same thing as guaranteeing they'll stay there. If you over-populate the Keep Pool, then its LRU mechanism will kick in and age its contents out just as efficiently as an unsegregated buffer cache would.
    Functionally, therefore, there can be no guarantees. The best you can do is create a sufficiently large Keep Pool, and then choose the tables that will use it with care such that they don’t swamp themselves, and start causing each other to age out back to disk.
    Thanks and Regards

  • When analytical queries create implicit temp tables?

    Hi,
    We have a DSS project on Oracle 9i Release 2 running on HP-UX. The project includes lots of SQL Analytical queries which handle huge data set, and makes lots of hash/merge joins and sorts. When I look at execution plans of the queries, I see that some of them create implicit temp tables and execute on it, but some not (creating window(buffer) ). I wonder how the optimizer decides to create implicit temp table when executing analytical queries. And also is three a SQL hint to force to create implicit temp table?
    Regards

    Hi,
    We have a DSS project on Oracle 9i Release 2 running on HP-UX. The project includes lots of SQL Analytical queries which handle huge data set, and makes lots of hash/merge joins and sorts. When I look at execution plans of the queries, I see that some of them create implicit temp tables and execute on it, but some not (creating window(buffer) ). I wonder how the optimizer decides to create implicit temp table when executing analytical queries. And also is three a SQL hint to force to create implicit temp table?
    Regards

  • HOW TO create a temp table or a record group at run time

    i have a a tabular form and i dont want to allow the user entering duplicate
    records while he is in insert mode and the inserted records are new and not exsisting in the database.
    so i want to know how to create a temp table or a record group at run time to hold the inserted valuse and compare if they are exsiting in previous rows or no.
    please help!

    As was stated above, there are better ways to do it. But if you still wish to create a temporary block to hold the inserted records, then you can do this:
    Create a non-database block with items that have the same data types as the database table. When the user creates a new record, insert the record in the non-database block. Then, before the commit, compare the records in the non-database block with those in the database block, one at a time, item by item. If the record is not a duplicate, copy the record to the database block. Commit the records, and delete the records in the non-database block.

  • Create local temp table

    I need to create a temp local table and look for ColdFusion informaiton, the cffile action write only can write text file, pictures is more to create file.
    I would like to know does ColdFusion support to create local temp tables on session start,
    If yes, should be able to get client temp directory and access the data using temp directory without using data source from ColdFusion server?
    Your help and information is great appreciated,
    Regards,
    Iccsi,

    Thanks for the information and help,
    I use jQuery combox to let user type selection from drop down box, but the table has more than 10,000 records which has performance issue. I would like to load to client machine to let user access locally to resolve performance issue using jQuery combo box,
    Thanks again for helping,
    Regards,
    Iccsi,

  • How to create a stored procedure that contains all 3 AFTER Triggers Update/Insert/Delete ?

    Hi guys, I'm trying to create a Stored procedure that will automatically add all 3 After triggers when executed on any given database, can someone please explain and give an example on how do I go about doing this ? I'd also like it to raise any errors
    that may come across, thanks in advance.

    Lets start with the question why do you need the triggers at all. Since SQL Server 2005 we can use an OUTPUT clause.
    This code can be re-written in SQL Server 2005 using the OUTPUT clause like below:
    create table itest ( i int identity not null primary key, j int not null unique )
    create table #new ( i int not null, j int not null)
    insert into itest (j)
    output inserted.i, inserted.j into #new
    select o.object_id from sys.objects as o
    select * from #new
    drop table #new, itest;
    go
    Now from this example, you can see the integration of OUTPUT clause with existing DML syntax.
    Another common scenario is auditing of data in a table using triggers. In this case, the trigger uses information from the inserted and updated tables to add rows into the audit tables. The example below shows code that uses OUTPUT clause in UPDATE and DELETE
    statements to insert rows into an audit table.
    create table t ( i int not null );
    create table t_audit ( old_i int not null, new_i int null );
    insert into t (i) values( 1 );
    insert into t (i) values( 2 );
    update t
       set i  = i + 1
    output deleted.i, inserted.i into t_audit
     where i = 1;
    delete from t
    output deleted.i, NULL into t_audit
     where i = 2;
    select * from t;
    select * from t_audit;
    drop table t, t_audit;
    go
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to find out the tables that will be affected using a transaction

    Hi,
    How to find out the list of database tables that will be affected when we use a standard transaction(ex. VA01, MM01..)...?(like When we create a salesorder, which tables and which fields will be affected..?)
    Is there any transaction or a simple way to find out the solution?
    Thanks,
    Pradeep.

    Hi,
    Give transaction code and in menu(system- status),  double click onthe Program name.
    Check in TOP INCLUDE - you will find all the tables related to that transaction.
    Thanks,
    Anitha

  • How to make table that will include controls such as drop list?

    How to make table that will include controls such as drop list?
    I need to create table as Property Browser of ActiveX, that include rows with differnt types such as drop list, color, ...

    Hi Nadav,
    I figured out where I missed your point. When you wrote
    table as Property Browser of ActiveX, that include rows with differnt types such as drop list, color, ...
    I was thinking mixed data-types in a [2d] table!
    Looking at the property browser again it looks like no single LV function can do all of that. It can be developed as a pop-up (like the browser is set-up) and then code all of the elegance using an event structure to control the background color of a string indicator while controling the visability of rings that are only made visable when a mouse down is detected. That will get you pretty close.
    So no, my previous response ws not correct for what you are trying to do if you want to duplicate all of the wistles and bells of the property browser pop-up window.
    Please forgive my distraction.
    Ben 
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Is it possible to create a configuration profile that will install multiple network printers and their associated drivers

    Is it possible to create a configuration profile that will install multiple network printers and their associated drivers?
    I was not able to find profile manager on my employer's installation of 10.6 Server. Is this only a feature of 10.7/10.8 server?

    10.6 server does not have profile manager, profile manager is only available in 10/7 and 10.8 server
    for 10.6 server you'll need to use wgm and server admin
    printer management with 10.6, I recommend you read the relevant server manuals regarding
    print server and user management, printer management

  • Create a clear button that will clear a jpanel

    so i have two classes. One being a frame, and the other being a panel.
    On the panel, i can draw various shapes with various colours etc. The frame contains the panel, and also a north panel containing various buttons to achieve this.
    What i would i need to do is create a clear button that will clear the panel.
    I know i can go and set it so it's draws a rectangle the same colour as the background but that would be cheating.
    I will post a section of the paint just so you get an idea.
        public void paintComponent(Graphics gPanel) {
            if (this.buffer == null) {
                Dimension d = getSize();
                this.buffer = new BufferedImage(d.width, d.height,
                        BufferedImage.TYPE_INT_ARGB_PRE);
                myLineColour = new Color(0, 255, 0);     // initial colour for drawing
                this.g2Buffer = (Graphics2D) this.buffer.getGraphics();
                this.g2Buffer.setColor(Color.white);
                this.g2Buffer.fillRect(0, 0, d.width, d.height);
                // This time we'll draw with a broad pen 
            g2Buffer.setStroke(new BasicStroke(myLineWidth));
            if (myShapeFlag == 1){{
                this.g2Buffer.setColor(Color.white);
                g2Buffer.setXORMode(myLineColour); //go into the overwrite mode
                g2Buffer.drawLine(xStart, yStart, xOld, yOld); // undraw last
                g2Buffer.drawLine(xStart, yStart, xEnd, yEnd);     // draw new
                g2Buffer.setPaintMode();          // out of XOR overwrite mode
                xOld = xEnd;                    // store last end point
                yOld = yEnd;
            if(mouseReleased) {          // final time through
                g2Buffer.setColor(myLineColour);
                g2Buffer.drawLine(xStart, yStart, xEnd, yEnd);     // draw final
                mouseReleased = false;
            gPanel.drawImage(this.buffer, 0, 0, this); }Any help on this would be much appreciated

    no idea how to do this.. sorry...
    for the jbutton action listenener i'm not sure.
    I think i'm on the right tracks with a method
        public void clearPanel(Graphics gPanel){
                g2Buffer.fillRect(100,100,100,100);     // draw final
                gPanel.drawImage(this.buffer, 0, 0, this);
    }but again i think i'm way off the mark..

  • Will the AirPort Express Base Station create a wifi connection that will enable me to wirelessly connect to XBOX live on my xbox 360

    will the AirPort Express Base Station create a wifi connection that will enable me to wirelessly connect to XBOX live on my xbox 360

    Yes, but not in all cases with it provide your with an "Open NAT" condition that some on-line gaming require. However, for most Xbox LIVE access, it should work just fine.

  • I am trying to create an executable vi that will call out another vi and show its front panel in the executable​. When I try this I recieve this error message "top level vi (my main vi) was stopped at unknown on the block diagram of (my sub vi)

    I am trying to create an executable vi that will call out another vi and show its front panel in the executable.  When I try this I recieve this error message "top level vi (my main vi) was stopped at unknown on the block diagram of (my sub vi)

    Well the most common way is to enclude the vi's in the build spec either directly in the dependancies that the App builder automatically generates OR by declaring them in the build spec as "additional enclusions" (like you must do for dynamic vi calls in your app.
    I have heard rummors about My.app Stuff.vi in a nugget Intaris posted- and I've wanted to dig deaper into Intaris' claims- but have not tried it myself.
    If you go down the stuff.vi route Keep us curious guys posted
    Jeff

  • Create a batch file that will loop a copy command that will call it as a task from another application

    I've created a script to copy large files from one system to another system. Unfortunately the transaction language of that system isn't feature rich, so I can't code a loop to copy multiple files to move concurrently. My goal is to create a batch file that
    will do the loop of copying multiple files, after being called by the application that is copying the large files one at a time. Can I get some pointer on how to do this? Basically, the code is like this:
    Copy from  \\Server_1\directory\sent_file.xyz
    To   \\Server_2\Directory\received_file.abc
    So the purpose is to perform the successful copy, then if the copy is good, execute the loop until completed.

    Might look around here.
    http://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=RootCategory&f%5B0%5D.Value=storage&f%5B0%5D.Text=Storage
    Or ask over here.
    MSDN Scripting forum
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

Maybe you are looking for

  • Hey Adobe, I need Rotate View in Illustrator please!

    Same as in Photoshop, preferably silky smooth. thank you

  • JavaScript is not working in MDS enabled site.

    I ran into problem when working in MDS mode. When running in MDS mode all variables declared as object initializers are undefined! FYI, I added all JS files as Custom Actions. The variable that I want to use is declared as: var ProjectImplementation

  • What is this Icon?  (Upper Right Finder Menu Bar)

    There is an icon on the upper right of the Finder menu that is all gray and is a thin vertical line with two equal sized triangles lined up on it on the right side, and a squiggly line going across the center of the line horizontally. I clicked on it

  • Can't open files after canceling sub

    I tried the Creative Cloud on a trial basis and then canceled. The problem now is that the latest Adobe Reader, which is no longer operating on my computer, is still the default program when I try to open a PDF. It won't let me open files. I have an

  • Printing same form with 4 copies with differnt terms for each copy..

    Hi experts, i have to print a invoice form same form should be printed with 4 copies like invoice copy, sales copy etc. for invoice copy the terms to b displayed is different similarly for sales copy. am able to print the differnt copies but the same