Cant Create Globla Temp Table

Hi,
I want to create one global temporary table in a package.procedure, i tried to create but it wont created, any reason why?
I tried in below:-
create or replace procedure GTT as
begin
execute immediate 'create global temporary table Test( SNO number);' ;
end;
And table is not created. Is there some thing wrong in the above procedure and please help me to resolve my problem.
Thanks in Adv.
Sandeep
Thanks.

If you really, really, really need to dynamically create tables, the owner of the procedure would require that the CREATE TABLE privilege be granted directly to the user, not through a role. CREATE ANY TABLE is a far more powerful and dangerous privilege that lets you create objects in other schemas.
However, and this is a big, huge however, I have never seen a situation where creating a temporary table dynamically in Oracle was a good idea. It almost always indicates someone that doesn't understand how Oracle temporary tables differ from temporary tables in other databases.
Justin

Similar Messages

  • 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

  • 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,

  • 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

  • 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.

  • Error while creating Global temp table

    Hi,
    I am very new to PL/SQL so please excuse my question. I have the below query . I have to get a count between the source table and various target tables. I am creating a global temp table to store the counts. I am getting the below error for my following query :
    Thanks for the help,
    Petronas
    ----Query----
    set serveroutput on
    Declare
    nm1 varchar2(200);
    nm2 varchar2(200);
    cnt1 number;
    cnt2 number;
    diff number;
    totdiff number;
    Begin
    nm1 := null;
    nm2:= null;
    cnt1:= 0;
    cnt2 := 0;
    diff := 0;
    totdiff := 0;
    create GLOBAL TEMPORARY TABLE diff ( name1 varchar(200), name2 varchar2(200), diff number);
    select count(*) into cnt1
    from users_staging;
    select count(*) into cnt2
    from PROD.users;
    nm1 := 'users_staging';
    nm2 := 'PROD.users';
    diff := cnt1 - cnt2;
    insert into diff values (nm1,nm2,diff);
    select count(*) into totdiff
    from diff
    where diff> 0 ;
    dbms_output.enable(10000);
    dbms_output.put_line('# of tables where difference is > 0 ' ||totdiff);
    end;
    Encountered the symbol "CREATE" when expecting one of the following:
    begin case declare end exception exit for goto if loop mod
    null pragma raise return select update while with
    <an identifier> <a double-quoted delimited-identifier>
    <a bind variable> << close current delete fetch lock insert
    open rollback savepoint set sql execute commit forall merge
    pipe

    Hi,
    "CREATE GLOBAL TEPORARY TABLE ..." is not a PL/SQL command; it is a SQL command only.
    Create the table, using that statement, before running the PL/SQL block.
    You can issue SQL statements from within PL/SQL using the EXECUTE IMMEDIATE command, but this is rarely a good idea.
    I assume the PL/SQL code is meant to create the table and then populate it.
    You should split those into two separate pieces of code. You'll only want to create the table once, no matter how many times you use it. I assume you'll want to populate it the same way many times. Remember, the "TEMPORARY" in "GLOBAL TEMPORARY TABLE" refers to the data, not the table. When you end a transaction (or a session, depending on whther you want "ON COMMIT DELETE ROWS" or "ON COMMIT PRESERVE ROWS"), the data disappears, but the now-empty stays, ready to be populated for the next transaction (or session).
    Edited by: Frank Kulash on Aug 4, 2010 2:25 PM

  • How to create the temp table in Sybase with values from Excel ?

    Dear Sir/Madam,
    I know this is not related with oracle DB, however i am in the need of help from you people who worked on Sybase. plz help me..
    I have the excel sheet which contains EmpId and EmpName values. I just wanted to read these two values one by one from an excel sheet and loaded them into one temp table in Sybase. is it possible thru sqlldr ?
    here is the sample code for your reference:
    begin tran
    create table tempdb..empIdName (emp_id int identity,emp_name varchar(50))
    go
    Awaiting for your valuable reply
    thanks
    pannar

    there is some hint provided by sybase user
    If it's Sybase IQ, you can export the excel file to a CSV file, then use a LOAD TABLE statement to get the data into your temporary table.
    For ASE, BCP would provide similar functionality.
    I am using ISQLW tool to work with sybase DB. what query to load the excel data to tem table in sybase. anyone who knows this? help me

  • Is there a way to create a temp table each time someone hits a procedure?

    I am creating a procedure in Oracle 10g to take data from Oracle to be put in a cognos report. The problem with creating a perminent table is that several people will be running this report at the same time, which means the procedure will be run each time someone runs this report. The perminent table will either drop the old data or the data will get mixed up which means the different peoples reports will not be correct. I tried putting a lock on the tables that would release the lock once one person was done running their report but that didn't work. I suggested we put the data directly into the cursor but what happens when more than one person runs this procedure at the same time?
    Any help on figuring out how to resolve this would be greatly appreciated.

    Hi,
    If there is one table 100 people inserting in the same table, i dont see a problem.
    Few things you will have to take care of.
    When you are retireving the data from teh table to show on the report,
    how will you identify it is for which user, obviously you store the user name too.
    Now this table will grow in size, so make sure when the report is exited you delete rows from teh table only pertainign to the user.
    Over a period of time you will face more problmes of slow response due to continous deletes because of something called as HWM.
    So make sure you also gatehr statistics for the table at regular intervals.
    So,
    1) Store user while isnerting, retrieve data only for that user in teh report
    2) delete data on report exit only for that user
    3) gather statistics for table at regual intervals.
    4) Ofcourse Build indexed for "good" response time, but Benchmark  against you data whatever you are doing.Cheers!!!
    Bhushan

  • Sntax error when creating a temp table

    Hi All,
    I get a syntax error when I try to create a  temporary table using the below sql statement.
    create global temporary column table prc as table precipitation;
    The  table precipitation exists in the database under my ID.
    Could anyone please let me know what is wrong with the above statement.
    Thanks,
    Goutham

    Try:
    create global temporary column table prc like precipitation;
    or
    create global temporary column table prc as (select * from precipitation);
    Cheers,
    Jody
    (HANA SQL Reference Manual:  https://websmp201.sap-ag.de/~sapidb/011000358700000604922011)

  • 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?

  • Create temp table using EXECUTE IMMEDIATE

    Is there any performance issue in creating globally temp table
    using EXECUTE IMMEDIATE or creating globally temp table from
    SQL PLUS.
    Any response will be greatly appreciated.
    null

    Anish,
    Creating tables is likely to be an expensive operation.
    Performance issues can only be considered in comparison to
    alternatives.
    Alternatives include: PLSQL tables, cursors and/or recoding so
    that tmp tables are not required. (One of our consultants reckons
    that sqlserver temp tables are usually used to get around
    limitations in sqlserver, ie slightly more complicated sql
    statements could be used instead of simpler sql and temporary
    tables).
    I would think creating the temp table once during sqlplus would
    be cheaper than creating and deleting it repeatedly at run time.
    Note that EXECUTE IMMEDIATE may do an implicit commit (dbms_sql
    certainly does). This may be got over my using the PRAGMA
    AUTONOMOUS_TRANSACTION; direction which places a
    procedure/function in a seperate transaction.
    Turloch
    P.S. We have some difficulty in getting information back from the
    field/customer sites. If you have questions and answers that are
    likely to be useful to other Oracle Migration Workbench
    users, and migrators in general, please send them in for possible
    inclusion in our Frequently Asked Question list.
    Oracle Migration Workbench Team
    Anish (guest) wrote:
    : Is there any performance issue in creating globally temp table
    : using EXECUTE IMMEDIATE or creating globally temp table from
    : SQL PLUS.
    : Any response will be greatly appreciated.
    Oracle Technology Network
    http://technet.oracle.com
    null

  • Can i create temp tables in command?

    I need to create 5 temp tables and then use in CR for display. can this be done in Command?

    p.s. if this is regarding the same report that you've been dealing with for a couple of weeks now, please let us know exactly how you want the data to come back:
    a)  do you want 5 rows of data from 5 queries each returning one value, or
    b) do you want 1 row of data from queries with 5 columns
    e.g.
    a)
    field1
    1.6
    2.1
    3.1
    1.8
    2.6
    or
    b)
    field1     field2     field3     field4     field5
    1.6          2.1      3.1          1.8     2.6
    the a) or b) choice will determine what methods you can use to retrieve the data.
    if you don't want either a) or b) please describe how you want the data returned.
    -jamie

  • Creating temp table within OPEN QUERY

    I am having trouble in creating a temp table within my OPEN QUERY.
    How do I modify the below script to do this?
    declare @sql nvarchar(max)
    set @sql =
    'SELECT *
    FROM audit.dbo.Comp AS a
    INNER JOIN audit.dbo.Pat AS b ON b.key = a.key
    AND b.reg = ''' + @id + '''
    INNER JOIN [prod].nfegh.dbo.flTest AS c ON c.id COLLATE Latin1_General_CI_AS = b.reg
    INNER JOIN (
    SELECT ''M1Q'' UNION ALL
    SELECT ''M0Q'' UNION ALL
    SELECT ''S1N''
    ) AS f(x) ON f.x = CLIN
    WHERE a.inv IN (''CR'', ''R'', ''EAT'')'
    set @sql = N'select * into MS_test1
    from openquery( ocles, ''' + replace (@sql , '''' , '''''') + ''' )'
    exec (@sql)

    OPENQUERY is designed to provide rows or to be user as target for DML.
    But even when this statement would create a temporary table, then it would be out of scope.

  • Unable to create Temp table in Data mover

    Hi dudes,
    i tried to create a Temp table in Datamover but could not. i have tried to run it in user mode as well as bootstrap mode, even though not get success. i have added my sample datamover script, please go through the scripts and notice my error.
    SET LOG D:\PT851\log\test1537.log;
    SET NO DATA;
    SET NO TRACE;
    CREATE_TEMP_TABLE test1537DB;
    SET OUTPUT D:\PT851\test1537.out;
    EXPORT test1537DB;
    and my error is,
    Error Message:- PeopleTools 8.51 - Data Mover Copyright (c) 2012 PeopleSoft, Inc. All Rights Reserved Started: Sun Dec 23 02:57:24 2012 **** PeopleSoft trace has been turned off Data Mover Release: 8.51 Database: C91TST (ENG) Ended: Sun Dec 23 02:57:24 2012 **** PeopleSoft trace has been turned back on Unsuccessful completion

    Is the record definition test1537DB existing?

Maybe you are looking for