How to drop a temporary table?

Hi ,
I try to create e temprary table with
create global temporary table My_table_name ( ..... ) ON COMMIT PRESERVE ROWS ;
All is OK.
I try this step:
insert into My_Table_name select ..... ;
All is OK.
After this I try :
delete from My_table_name ;
All is OK.
But if I try to make:
drop table My_table_name , Oracle reports that I can not drop this table ( the table is in use).
Where is the problem?
Many thanks in advance.
null

Hi,
You have created a session specific table which will only be dropped when you come out of the session. if you want to drop in the same session try using on commit delete rows that is the transaction specific table.
regards
gaurav
null

Similar Messages

  • How to drop/remove temporary tables from TempDB

    Hi,
    I do have multiple temp tables with same prefix but with different code at the end. How do i drop them i am sure there is no active connections to it as the created date is from two months ago. I am currently using SQL Server 2005 Sp2 version want to know
    if its a bug in that version as the temp tables are not being dropped. 
    1.The temp tables are being created in Stored procedure
    2. The stored procedure is being executed by a sql agent job
    3. The sql agent job keeps failing as the stored proc fails half way thru the code 
    4. Does it not drop the temp tables if the stored proc is being executed by agent job and fails ?  does it not consider as session closed ?
    Please let me know if needed any more details on it. 
    Thanks, Sri The journey is what brings us happiness not the destination―Dan Millman

    Hi Uri..
    Yes, thats what i have read but i still have ten temp tables with same prefix and different session code at the end . I am sure there are no open/active sessions tied to them .want to know if there is a bug with SQL server 2005 SP2 version  ?
    I am executing the stored proc using SQL Agent job so when it fails does it end the session ? if not how do i do it ?
    if i add the below query to the proc does it drop rest of the old temp tables ?
    IF EXISTS (
    SELECT *
    FROM sys.tables
    WHERE name LIKE '#temp%')
    DROP TABLE #temp
    Thanks, Sri The journey is what brings us happiness not the destination―Dan Millman

  • Creating and Dropping a temporary table in Bi publisher?

    Hi all.
    My database is sybase.
    I created a new data set in BI publisher where it creates a temporary table,
    uses that temp table in a select query and then I dropped the temporary table.
    I wrote all these 3 SQL statements in a single dataset.
    This is executed for the first time with out any errors.
    The second time I am tryiong to run the report..It says It cannot create temp table as it has one temp table with the same name.
    When I execute the same query in my database (SQL developer) this works. But not working in BI publisher.
    Please suggest.

    I came across this thread...in this forum while looking for a solution..
    Can i create temporary table with BI Publisher ?
    If we have to use a data template...Does the function in data trigger necessarily needs to be a PL/SQL function? because..we donot use oracle database. we use T-SQL to write queries..

  • How to Create a Temporary Table with SQL Server

    I know you can create a temporary table in SQL Server 2000, but not quite sure how to do it in CFMX 7, i.e., does the SQL go inside a <CFQUERY dbtype="query"> tag?
    I'm pulling the main set of records from an Oracle server (1st data source), but it does not contain employee names, only employee IDs.  Since I need to show the employee name along with the Emp ID, I'm then pulling a list of "current" employee names from a SQL Server (2nd data source), which is the main database on our CF server.
    I've got a QofQ that works fine, except it only matches EmpIDs that exist in both result sets.  Employees who are no longer employed, don't match, and don't display.  Since I can't do a LEFT OUTER JOIN with a QofQ, what I need to do is get the records from the Oracle server into the SQL Server.  Preferably in a temporary table.
    I was hoping if I could get those Oracle records written to a temp table on the main SQL Server, in same database as the Employee Name table, I could then write a normal <CFQUERY> that uses a LEFT OUTER JOIN.
    I think I could probably write a Stored Procedure that would execute the SQL to create the temporary table, but am trying to avoid having to write the SP, and do it the simplest way.
    This query will be a program that can be run hundreds of times per day, with a form that allows users to select date ranges, locations, and other options.  That starts the queries, which creates the report.  So I just need the temp table to exist only until all the SQL has run, and the <CFOUTPUT> has generated a report.
    If the premise is right, I just need some help with the syntax for creating a SQL Server temp table, when you want to write records to it from an external data source.  I'm trying the following, but getting an error:
    <CFQUERY name="ITE_Temp" datasource="SkynetSQL">
    CREATE TABLE #MyTemp
    (   INSERT INTO #MyTemp
    ITE2.TrueFile char (7) NOT NULL,
    ITE2.CountOfEmployee int NULL,
    ITE2.DTL_SUBTOT decimal NULL,
    ITE2.EMPTYPE char (3) NULL,
    ITE2.ARPT_CD char (3) NULL
    </CFQUERY>
    So I actually created a permanent table on the SQL Server, and wrote the below SQL, which does work, and does write the records to table.  I can then write another CFQUERY with a LEFT OUTER JOIN, and get all the records, including those that don't have matching employee name:
    <CFQUERY datasource="SkynetSQL">
    <CFLOOP index="i" from="1" to = "#ITE2.RecordCount#">
    INSERT INTO ITE_Temp
       (FullFile,
       EmployeeCount,
       DTL_Amount,
       EmployeeType,
       station)
    VALUES  ('#ITE2.TrueFile[i]#',
       #ITE2.CountOfEmployee[i]#,
       #ITE2.DTL_SUBTOT[i]#,
       '#ITE2.EMPTYPE[i]#',
       '#ITE2.ARPT_CD[i]#')
    </CFLOOP>
    </CFQUERY>
    But, I hate to have to create a table and physically write to it.  For one, it seems slower, and doing it in temp would be in memory, and probably much faster, correct?  Is there some way to code the above, so that it does something similar, but in a TEMPORARY TABLE?   If I can figure out how to do this, I can pull data from multiple data sources and servers, and using SQL Server temp tables, work with the data as if it was all on the same SQL Server, and do some cool reports.
    Everything I've done for the past few years, has all been from data from a single source, whether SQL Server, or another server.  Now I need to start writing reports where data can come from 3 or 4 different servers, and be able to do joins (inner and outer).  Thanks for any advice/help.  Much appreciated.
    Gary

    While waiting to hear back, I was able to write the query results from an outside Oracle server, to a table on the local SQL Server, and do the LEFT OUTER JOIN required for the final query and report to work.  That was with this syntax:
    <CFQUERY name="AddTableRecords" datasource="MyTable">
    TRUNCATE TABLE ITE_Temp
    <CFOUTPUT query="ITE2">
    INSERT INTO ITE_Temp
    (FullFile,EmployeeCount,DTL_Amount,EmployeeType,station)
    VALUES
    ('#TrueFile#', #CountOfEmployee#, #DTL_SUBTOT#, '#EMPTYPE#', '#ARPT_CD#')
    </CFOUTPUT>
    </CFQUERY>
    However, I was not able to write to a temporary table AND read the results. I got the syntax to run to write the above results to a temporary table.  But when I tried to read and output the results from the temp table, I got an error.  Also, it wouldn't take the single "#" (local) only the global "##" table var, using this syntax.  Note that if I didn't have the DROP TABLE in the beginning, the 2nd time you run this query, you get an error telling you the table already exists.
    <CFQUERY name="ITE_Temp2" datasource="MyTable">
    DROP TABLE ##MyTemp2
    CREATE TABLE ##MyTemp2
    FullFile char (7) NOT NULL,
    EmployeeCount int NULL,
    DTL_Amount decimal NULL,
    EmployeeType char (3) NULL,
    station char (3) NULL
    <CFOUTPUT query="ITE2">
    INSERT INTO ##MyTemp2 VALUES
    '#ITE2.TrueFile#',
    #ITE2.CountOfEmployee#,
    #ITE2.DTL_SUBTOT#,
    '#ITE2.EMPTYPE#',
    '#ITE2.ARPT_CD#'
    </CFOUTPUT>
    </CFQUERY>
    So even though the above works, I could use some help in reading/writing the output.  I've tried several things similar to below, but they don't work.  It't telling me ITE_Temp2 does not exist.  It's not easy to find good examples of creating temporary tables in SQL Server.
    <CFQUERY name="QueryTest2" datasource="SkynetSQL">
    SELECT *
    FROM ITE_Temp2
    </CFQUERY>
    <CFOUTPUT query="ITE_Temp2">
    Output from Temp Table<br>
    <p>FullFile: #FullFile#, EmployeeCount: #EmployeeCount#</p>
    </CFOUTPUT>
    Thanks for any help/advice.
    Gary.

  • How to drop a temp table in bi publisher

    Hi
    We are using Bi publisher 10g with sybase and we have a query which uses temporary table
    Below is the sample T-sql query
    Ex :
    Select column1,column2 into temp_table from table1
    Select column1 from temp_table
    drop temp_table
    We are not able to drop the temp_table in bi publisher. We tried using functions to place them in 'After Trigger' of bip but the sybase function does not allow 'Drop' command to be used in it.
    Also, Does 'exec' command work on bip?
    Can some one please suggest a solution

    Yes that is the only option which we can stop a running report in BI Publisher
    I suspect you'll need to ask your DBA to kill the session.
    However, if you have DBA privileges yourself, you can do this by a few methods, some of which are described here:
    http://www.oracle-base.com/articles/misc/KillingOracleSessions.php
    Mark if helps,
    Thanks,

  • How Create a Global Temporary Table inside a Stored Procedure?

    Hi...
    I need to create a Global Temporary Table inside a Stored
    Procedure....
    I have no idea how to do that....
    Please....if u can send me a sample, send to me....
    Thanks a lot

    there are many ways to do this..
    one u can use dbms_utility package to run ddl statements like
    for ex:
    declare
    t varchar2(200):='order_no';
    v number;
    begin
    --dbms_utility.exec_ddl_statement('select '||t||' into '||v||'
    from
    --ordermaster where rownum=1');
    dbms_utility.exec_ddl_statement('create table cvt(t number)');
    dbms_output.put_line(v);
    end;
    but the actual method(recommended) involves a bit coding using
    dbms_sql package you will find examples on technet or metalink
    to use this package..
    I hope this helps
    Narendra

  • Dropping global temporary table

    Hi: I am on 10.2.0.3.
    I have an interesting problem with global temporary tables.
    I created a few and was using them for awhile.
    Now I am trying to drop one (it has a couple indexes as well) and here is what I am getting:
    SQL> drop table sysadm.PS_BPA_RATES_TA011;
    drop table sysadm.PS_BPA_RATES_TA011
    ERROR at line 1:
    ORA-14452: attempt to create, alter or drop an index on temporary table already in use
    Needless to say I checked the active sessions (using v$session) but there is none which locks this table.
    I truncated it (although it had 0 rows but I was trying to free up space), also tried to flush shared_pool & buffer_cache (it's a test DB) - which were successful but did not help - I am getting the same error.
    Someone suggested checking V$TEMPSEG_USAGE where segtype='DATA'. This view shows 3 rows with session# & sql_id but both does not show any session:
    SQL> select * from V$TEMPSEG_USAGE where segtype='DATA';
    USERNAME USER SESSION_ADDR SESSION_NUM SQLADDR SQLHASH SQL_ID
    TABLESPACE CONTENTS SEGTYPE SEGFILE# SEGBLK# EXTENTS BLOCKS SEGRFNO#
    SYSADM SYSADM C00000021C1D2318 123 C0000002DB467ED0 146923226 0ahnqxh4c3rqu
    TEMP TEMPORARY DATA 204 465289 1 128 4
    SYSADM SYSADM C00000021C1CE508 32644 C00000021B6D3F58 2784120300 0c5411akz4mgc
    TEMP TEMPORARY DATA 204 506761 14 1792 4
    SYSADM SYSADM C00000021C1CE508 32644 C00000021B6D3F58 2784120300 0c5411akz4mgc
    TEMP TEMPORARY DATA 204 505993 1 128 4
    SYSADM SYSADM C00000021C1CE508 32644 C00000021B6D3F58 2784120300 0c5411akz4mgc
    TEMP TEMPORARY DATA 204 505865 1 128 4
    SQL> select session_num,sql_id from V$TEMPSEG_USAGE where segtype='DATA';
    SESSION_NUM SQL_ID
    123 0ahnqxh4c3rqu
    32644 0c5411akz4mgc
    32644 0c5411akz4mgc
    32644 0c5411akz4mgc
    SQL> select sid,serial#,process from v$session where sql_id='0ahnqxh4c3rqu';
    no rows selected
    SQL> select sid,serial#,process from v$session where sid=32644;
    no rows selected
    I know that recycling the database should help but I can not do it right now - and I am sure there should be a solution.
    Any help appreciated. TIA,
    GregX

    I found a solution to this.
    You have to use V$TEMPSEG_USAGE where segtype='DATA'.
    Column session_num corresponds to serial#. The job was canceled from the front end but this session was still hanging in there. After I killed it the drop worked.
    Lots of people are saying that truncate should help with this problem. That's not true.

  • How to use Oracle temporary table and verify if it exists

    1. I got two errors on the following code.
    ORA-06550: line 13, column 4:
    PLS-00428: an INTO clause is expected in this SELECT statement
    ORA-06550: line 17, column 3:
    PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
    2. Can I include this code in the create view statement?
    Thanks ahead, I am new to oracle dev world.
    ===========================================================
    DECLARE
    l_count NUMBER;
    BEGIN
    select count(*)
    into l_count
    from all_tables
    where table_name like 'TEMP_SHOW_STAFF_2%';
    if l_count > 0 then
    select * from TEMP_SHOW_STAFF_2;
    else
    create global temporary table TEMP_SHOW_STAFF_2
    (employee_id Number,
    last_name varchar(10),
    first_name varchar(10),
    salary_amount varchar(10))
    on COMMIT delete rows;
    end if;
    END;

    The PL/SQL User's Guide will have much more information, but as a quick example (new_dept is an empty table with the same structure as the DEPT table in the SCOTT schema).
      1  declare
      2    -- Create the type & declare a variable of that type
      3    type dept_arr_typ is table of dept%rowtype;
      4    dept_arr dept_arr_typ;
      5  begin
      6    -- Populate the type in memory
      7    select *
      8      bulk collect into dept_arr
      9      from dept;
    10    -- Manipulate the data
    11    for i in 1..dept_arr.count
    12    loop
    13      select 'foo'
    14        into dept_arr(i).dname
    15        from dual;
    16    end loop;
    17    -- Write the data back
    18    for i in 1..dept_arr.count
    19    loop
    20      insert into new_dept( deptno, dname, loc )
    21        values( dept_arr(i).deptno, dept_arr(i).dname, dept_arr(i).loc );
    22    end loop;
    23* end;
    SCOTT @ nx102 Local> /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.01
    SCOTT @ nx102 Local> select * from new_dept;
        DEPTNO DNAME          LOC
            10 foo            NEW YORK
            20 foo            DALLAS
            30 foo            CHICAGO
            40 foo            BOSTONOf course, for this sort of thing, we could do everything in a single SQL statement
    INSERT INTO new_dept( deptno, dname, loc )
      SELECT deptno, 'foo', loc
        FROM dept;Collections can be handy if you need to apply a bit more conditional logic, though.
    Justin

  • How to create a TEMPORARY table in memory?

    Hi,
    Is there any way to create a temporary table in memory other than in tablespce?

    A cursor should do the job for you, I reckon.
    Regards,
    Raymond.

  • How could I drop temporary table in preserve rows?

    Hi,
    I created a global temporary table test with the option, on commit preserve rows.
    I try to drop it with another session but I can't, I always have the error message :
    ORA-14452. So what can I do?
    Thanks.

    We cannot drop a temporary table if a session is using it. This means once a session has inserted data into it we cannot drop the table until that session either commits or exits (depending on whether the table is of the type PRESERVE ROWS). You can see this by looking in v$lock.
    If you quit out of your first session the second session will be able to drop the table.
    Cheers, APC

  • How create temporary table from list of values

    Can you anybody advise me how can I create temporary table from list of values? I have list of values and need create temporary table for next use with command JOIN etc.
    Thank you for help

    NO, you can not create temporary table in oracle on the fly ( Like #Tabels in SQl Server or Sybase ) , you will have to use the GTT i.e Global Temporary Tables
    check the following link GTT :
    to flush the tables after commit
    CREATE GLOBAL TEMPORARY TABLE my_temp_table (
      column1  NUMBER,
      column2  NUMBER
    ) ON COMMIT DELETE ROWS;In contrast, the ON COMMIT PRESERVE ROWS clause indicates that rows should be preserved until the end of the session.
    so to keep rows in Table after commit
    CREATE GLOBAL TEMPORARY TABLE my_temp_table (
      column1  NUMBER,
      column2  NUMBER
    ) ON COMMIT PRESERVE ROWS;

  • Create Temporary Tables

    Hi, there.
    Can anybody tell me what's the syntax for the SQL statements to create temporary tables?
    I'm developing a shopping cart, and at the end of every purchase (checkout) I want to organize the items of the Session Bean Hash Table that contains them, and group them by category, brand, price and show the serial number of each item. I was thinking to do SQL-style operations like GROUP BY on the Hash Table itself, but I am having a hard time with it, so that's why I thought that filling a temporary database table with the Hash Table data could be the solution to the problem of grouping and ordering the items contained in the Shopping cart Bean.
    I saw the following code in this same forum:
    stmt = con.createStatement();
    stmt.executeUpdate("create table temp (slno integer, first_name varchar(32), middle_name varchar(1), last_name varchar(32))");
    But I don't understand how the temporary table has a fixed name, isn't that going to create conflict with another user that creates a temporary table with the same name but in a different session?
    I hope my approach makes sense. If so, what's the SQL syntax to create temporary-session-like tables so I can include it in my JDBC code?
    Thank you in advance for any information or alternative suggestion.

    But I don't understand how the temporary table has a
    fixed name, isn't that going to create conflict with
    another user that creates a temporary table with the
    same name but in a different session?Yes, it is. That's one reason why people try to avoid creating temporary tables, I suppose. There are other reasons.
    I hope my approach makes sense. If so, what's the SQL
    syntax to create temporary-session-like tables so I
    can include it in my JDBC code?You already know the syntax for creating a table. Your only problem is finding a unique name for the table, one that no other user will use. You could have a one-row one-column table with a number in it, which you read and increment, then use that number for your table name, for example. Unless your database happens to have this as a feature -- you would have to read its documentation to find that out.
    However as I implied before, you should try to avoid creating temporary tables. Creating a table is a time-consuming operation, and if your program ends abnormally without dropping the temporary table, your database slowly fills up with useless tables.

  • Global temporary table

    Hi
    how to create global temporary table and push data from forms.
    Thanks
    Shital

    hi
    try something like this.
    CREATE GLOBAL TEMPORARY TABLE my_temp_table (
      column1  NUMBER,
      column2  NUMBER
    ) ON COMMIT DELETE ROWS;If its Correct/Helpful please Mark it thanks.
    Sarah

  • Using temporary tables with a ref. cursor

    I want to use a temporary table to populate certain data and then return a ref cursor fetching data from the temporary table.
    1. Will this approach work ?
    2. Do I need to drop the temporary table ? Can I drop the table as a last statement in the stored proc (remember a ref cursor based on this table is to be returned as a out parameter).
    Please help.

    1. Will this approach work ?Sort of, just like it is possible to dig a trench with a spoon. It can be done, but why can't you just write a select that returns the data without storing intermediate versions of your processing somewhere.
    2. Do I need to drop the temporary table ?No. and you shouldn't.
    Can I drop the table as a last statement in the stored proc
    (remember a ref cursor based on this table is to be returned as a out parameter).No.
    If you really need to use a temporary table, it should be created one time when the application is installed, and should never be created in code.

  • Help Please:  Need To Create Temporary Table

    Hi Guys,
    I am a new Oracle user. I need to create this report that uses
    temporary table. I can't use "create" statment in the sql
    query. Now wihtout that I don't know how to create the
    temporary table. Please let me know if anyone has any
    suggestions.
    Thanks a billion
    Sam

    Hi Sam,
    yes, you can't apply neither Data Definition Language (DDL) nor
    Data Manipulation Language (DML), except SELECT statement, at
    the query builder inside your report. You may create a stored
    procedure containing the DDL or the DML, then run this stored
    procedure at the "Before Report" trigger. You can find this
    trigger under Report Triggers of your Object Navigator.
    hope this help you.
    have a nice day...
    daniel

Maybe you are looking for