How can i 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

To create a global temporary table inside a stored procedure,
the minimal syntax would be:
CREATE OR REPLACE PROCEDURE procedure_name
AS
BEGIN
EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE table_name'
|| '(column_name NUMBER)';
END procedure_name;
As Todd stated, it would probably be better to create the global
temporary table outside of the procedure:
SQL> CREATE GLOBAL TEMPORARY TABLE table_name
2 (column_name NUMBER);
Table created.
You can also specify things like ON COMMIT PRESERVE ROWS or ON
COMMIT DELETE ROWS.
It may be that there is something else, like a PL/SQL table of
records or a cursor, that would suit your needs better. It is
difficult to guess without knowing what you want to do with it.

Similar Messages

  • 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

  • Global temporary table in a store procedure

    Hi,
    I REALLY need to create a global temporary table in a stored procedure but I don't know how .........
    My solution was
    create or replace procedure test(
    as
    begin
    execute immediate 'create global temporary table t(x number,..) ;';
    end;
    but the table is not created. What I am doing wrong and how to resolve the problem?
    Thanks.

    There is NO valid reason to create a GTT on the fly (except during installation of a package). This defeats the entire logic behind it. Precreate it and use it by a million users at the same time and it won't care. For more information On GTT's see.
    http://download-west.oracle.com/docs/cd/A87860_01/doc/appdev.817/a76939/adg03sch.htm#7807

  • Creating a Global Temporary Table on non-default TEMP tablespace.

    Hello ,
    I am using Oracle 11g.
    I have a procedure which create global temporary tables for its functionality. As the data which is going in the global temporary table , mean the data which is going in the default TEMP tablesapce is too huge ..... billions of rows..
    So what i want to do is , I want to create the global temporary table in another TEMP2 tablespace ( which is not the default one) so the load of billions of rows of data will be shifted to TEMP2. The default TEMP tablespace will not be affected and it can be used for other transactions.
    Is this possible. Can i shift the global temporary table from TEMP( Default temp tablespace) to TEMP2 ( the non-default temp tablespace) ????
    Please guide me with proper solutions and examples ....
    Thanks in advance ..

    DBA4 wrote:
    Hello ,
    I am using Oracle 11g.
    I have a procedure which create global temporary tables for its functionality. As the data which is going in the global temporary table , mean the data which is going in the default TEMP tablesapce is too huge ..... billions of rows..
    So what i want to do is , I want to create the global temporary table in another TEMP2 tablespace ( which is not the default one) so the load of billions of rows of data will be shifted to TEMP2. The default TEMP tablespace will not be affected and it can be used for other transactions.
    Is this possible. Can i shift the global temporary table from TEMP( Default temp tablespace) to TEMP2 ( the non-default temp tablespace) ????
    Global temporary tables are instantiated in the temporary tablespace of the schema that inserts the data - not into "the default" temporary tablespace.
    Assume Schema1 creates a GTT and grants all on that table to schema2
    Assume schema1 also creates a procedure (authid owner, the default) to insert data into the GTT and grants execute on the procedure to schema2
    If schema2 executes: insert into schema1.gtt, the data will appear in the temporary tablespace of schema2
    If schema2 executes: execute schema1.procedure, the data will appear in the temporary tablespace of schema1
    So if you want to protect the "normal" temporary tablespace, you could just create a special temporary tablespace for the owner of the procedure.
    Regards
    Jonathan Lewis

  • How can I create a query with tables in INFOSET?

    Dear Gurus,
    How can I create a query with tables in INFOSET?
    Just tables and fields INFOSET?
    Kind Regards,

    Hello
    Check following SCN Article for your understanding/reference:
    - [Using Infoset Query ,SAP Query and Quick Viewer|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/10eab7af-0e54-2c10-28a5-87b47adbe1a5]
    Regards
    JP

  • How can I implement the connection pool in my java stored procedure

    my java stored procedures (in database 'B') have to connect to another oracle database ,let's say 'A'. And how can I implement the behavior like the so-called connection pool in my java stored procedure in 'B', as below.
    1. database B, has 2 java stored procedures sp1 and sp2
    2. both sp1 and sp2 connects to databse 'A'
    whatever I call the sp1 and sp2 and the database 'A' always only one connected session from sp1 and sp2 in database 'B'.
    THANKS A LOTS...

    my problem is I have a lots of java stored procedures need to cnnect to the remote oracle db, and I hope the remote db can only have a connected session from my java stored procedures in my local db. I try as below
    class sp{
    static Connection conn=null; //the remote db connection,
    public static void sp1(){...}//procedure 1, using conn
    public static void sp2(){...}//procedure 2, using conn,too
    I can 'see' the 'conn' variable if I invoke the sp1() and sp2() from the same client application(maybe sqlplus). But if I invoke the sp1() from client 'A' and invoke sp2() from client 'B' then the sp1() and sp2() can not see the 'conn' variable for each other. I think it's because the two clients cause oracle to create two instances of the class 'sp' and the sp1() and sp2() located in different instance seperately. Thus the sp1() and sp2() can not see 'conn' for each other. They can only see its own 'conn'.
    To connect to the remote db from the java stored procedure is easy but is it possible to connect to the remote db via database link from the java stored procedure at my local db ? If so, then I also archive my goal .
    BTW , thanks a lots...
    andrew :-)

  • How can I use a button to trigger a SQL Stored Procedure?

    I have a stored procedure (UpdateAdsUsers) that performs updates on multiple tables all tied together with one
    parameter - @username
    (I'm using DWCS5, SQL SERVER 2008, ASP VB)
    UPDATE users SET defaultview='0' WHERE user_name=@username
    UPDATE db_settings SET valuestr='MM/DD/YYYY' WHERE keyword='dateformat' AND user_name=@username
    UPDATE db_settings SET valuestr='Y' WHERE keyword='COPY_MSG_VIA_EMAIL' AND user_name=@username
    UPDATE db_settings SET valuestr='4' WHERE keyword='web_download_rend' AND user_name=@username
    UPDATE db_settings SET valuestr='Y' WHERE keyword='cpy_confirm' AND user_name=@username
    UPDATE db_settings SET valuestr='WLPG:12' WHERE keyword='INITIAL_ASSETS' AND user_name=@username
    UPDATE db_settings SET valuestr='20' WHERE keyword='thumb_disp_row' AND user_name=@username
    UPDATE db_settings SET valuestr='20' WHERE keyword='text_disp_row' AND user_name=@username
    UPDATE db_settings SET valuestr='5' WHERE keyword='para_disp_row' AND user_name=@username
    UPDATE db_settings SET valuestr='a.editorial.company_name' WHERE keyword='sortorder1' AND user_name=@username
    UPDATE db_settings SET valuestr='a.editorial.title' WHERE keyword='sortorder2' AND user_name=@username
    UPDATE db_settings SET valuestr='a.editorial.production_type' WHERE keyword='sortorder3' AND user_name=@username
    UPDATE tnailview_fields SET rendition='1', first_field='company_name', second_field='title', third_field='adsx_type', fourth_field='adsx_status' WHERE user_name=@username
    UPDATE textview_fields SET rendition='1', first_field='company_name', second_field='title', third_field='title_desc', fourth_field='production_type', fifth_field='audio_summary', sixth_field='totalruntime', seventh_field='adsx_type', eighth_field='adsx_status' WHERE user_name=@username
    UPDATE paraview_fields SET rendition='1', first_field='company_name', second_field='title', third_field='title_desc', fourth_field='production_type', fifth_field='audio_summary', sixth_field='totalruntime', seventh_field='adsx_type', eighth_field='adsx_status' WHERE user_name=@username
    SELECT * FROM adsx_preferences WHERE user_name=@username
    This functions perfectly in SQL.
    Using Dreamweaver CS5, I've added the Procedure as a Command (ADS_User) with the one variable (@username).
    <%
    set ADS_User = Server.CreateObject("ADODB.Command")
    ADS_User.ActiveConnection = MM_ADSX_STRING
    ADS_User.CommandText = "dbo.UpdateAdsUser"
    ADS_User.Parameters.Append ADS_User.CreateParameter("@RETURN_VALUE", 3, 4)
    ADS_User.Parameters.Append ADS_User.CreateParameter("@username", 129, 1,32,ADS_User__username)
    ADS_User.CommandType = 4
    ADS_User.CommandTimeout = 0
    ADS_User.Prepared = true
    ADS_User.Execute()
    %>
    In a perfect world, either an image click or a form submit would run the procedure.  The parameter (@username) is currently sent to the page as a URL Querystring of the same name.
    I'm sure it's something obvious, but I'm new.
    Thanks in advance

    I'm not sure what your question is. Is this currently failing? Or are you not able to figure out how to send the username to the script page? You really just need to create a form and pass the value in a form field.
    >The parameter (@username) is currently sent to
    >the page as a URL Querystring of the same name.
    Never use a querystring to update data. It is too dangerous. Use the post method instead.

  • How can i Create a PROGRESSIVE BAR   while process of a procedure is going

    hi,
    I have a push button in my form that runs the procedure .the process will approx 15 minutes. while processing is started, i want to display PROGRESSIVE BAR
    until process complete and exits automatically after process . please suggest me how to create the same, is it possible..
    please send me solution as soon as possible please
    thanks in advance
    prasanth

    The forms demos contains a progress bar bean which you can use if web deployed.
    Regards
    Grant Ronald
    Forms Product Management

  • How can I write to a (external)file from a stored procedure

    I want to write some data to a (external) file. I have it working with the function UTL_FILE.
    My problem is I want to write to a file on a mapped drive (so a drive on a different machine). This is not working.
    Does anyone know a way to build this.
    Please send your responses to [email protected]
    Many thanks,
    Alex Nagtegaal

    an extraction out of expert one-on-one from Thomas Kyte
    <quote>
    when an oracle istance is created the services that support it are setup to 'log on as' the system (or operating system) account, this account has very few privileges and no acces to Window NT Domains. To access another Windows NT machine the OracleServiceXXXX must be setup to logon to the appropriate Windows NT Domain as a user who has acces to the required location for UTL_FILE.
    To change the default logon for the Oracle services go to (in Windows NT):
    Control Panel | Services | OracleServiceXXXX | startup | log on as; (where XXXX is the instance name)
    In Windows 2000, this would be:
    Control Panel | Administrative Tools | Services | OracleServiceXXX | Properties | Log on tab; (again XXXX is the instance name)
    Choose the This Account radio button, and then complete the appropriate domain login information. ONce the services have been setup as a user with the appropriate privileges, ther are two options dfor setting UTL_FILE_DIR:
    * Mapped Dirve: To use a mapped drive, the user that the service starts as must have setup a drive to match UTL_FILE_DIR and be logged onto the server when UTL_FILE is in use.
    * Universal Naming Convention: UNC is preferable to Mapped Drives because it does not require anyone to be logged on and utl_file_dir should be set to a name in the form \\<machine name>\<share name>\<path>
    You will of course need to stop and restart Oracle after changing the properties of the service.
    <\quote>
    I want to write some data to a (external) file. I have it working with the function UTL_FILE.
    My problem is I want to write to a file on a mapped drive (so a drive on a different machine). This is not working.
    Does anyone know a way to build this.
    Please send your responses to [email protected]
    Many thanks,
    Alex Nagtegaal

  • Create view for Global Temporary Table

    if view is create for global temporary table so exactly how it works which helps regarding application performance.
    Regaards,
    Sambit Ray

    A view is just a stored query. It can be on global temporary tables or regular one, makes no difference.

  • Create global temporary table in delete trigger

    Hi to all, I am triyng to create a global temporary table in trigger so i can hold all the deleted rows and do some stuff after the statement which uses the table that fires the trigger.
    In this way I am trying to avod mutating table error. but the following trigger gives error.
    create or replace
    TRIGGER TD_EKSINAVLAR
    FOR DELETE ON DERSSECIMI_EKSINAVLAR
    COMPOUND TRIGGER
    BEFORE STATEMENT IS
    BEGIN
    CREATE GLOBAL TEMPORARY TABLE DELETED_ROWS
    AS ( SELECT * FROM DERSSECIMI_EKSINAVLAR WHERE 1 = 2 )
    ON COMMIT DELETE ROWS;
    END BEFORE STATEMENT;
    BEFORE EACH ROW IS
    BEGIN
    NULL;
    END BEFORE EACH ROW;
    AFTER EACH ROW IS
    BEGIN
    NULL;
    END AFTER EACH ROW;
    AFTER STATEMENT IS
    BEGIN
    NULL;
    END AFTER STATEMENT;
    END TD_EKSINAVLAR;
    the error is
    Error(12,5): PLS-00103: Encountered the symbol "CREATE" when expecting one of the following: ( begin case declare exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge
    Please help me about the situation.
    Thanks in advance.
    Gokhan

    Karthick you are absolutly right
    Our main process is to migrate sql server 2000 database to oracle 11g and I am stuck with the triggers that reference to table that fires the trigger itself.
    Can you help me about how i can overcome mutating table errors using compund triggers? Espacially for the situation that one statement tries to update or delete multiple rows on a table.
    You can understand my logic from the above code. I want to hold all the affected rows in a table and in after statement body using a cursor on that table I want to do required changes on the table. How can I do that or how should I do ?
    regards.

  • What is the syntax for creating global temporary table using a select query

    hii
    I'm creating a global temporary table using a select query ..how to mention 'on commit preserve rows' that?
    create global temporary table t1 as select * from trn_ordbase on commit preserve rows;
    but this is invalid syntax,so how to mention on commit preserve rows in this???if i dont mention it ,by default its considering as on commit delete rows.
    Please help me out of this problem.

    create global temporary table t1 as select * from trn_ordbase on commit preserve rows;You CANNOT use this syntax.
    http://download-east.oracle.com/docs/cd/B19188_01/doc/B15917/sqcmd.htm
    http://download-east.oracle.com/docs/cd/B19188_01/doc/B15917/glob_tab.gif
    http://download-east.oracle.com/docs/cd/B19188_01/doc/B15917/cre_tabl.gif

  • Problem creating index on global temporary table

    Running Oracle DB Oracle9i Release 9.2.0.7.0.
    I'm trying to create 3 indexes on a temporary table, the first index creates fine but the other remaining 2 result in the following error:
    ERROR at line 1: ORA-00600: internal error code, arguments: [kftts2bz_many_files], [0], [20], [], [], [], [], []
    Have tried searching with not much success, any pointers, tips, hints would be appreciated, below is the table and the indexes:-
    create global temporary TABLE contacts (
    ID VARCHAR2(20) NOT NULL,
    DOB VARCHAR2(8),
    HH_LASTNAME VARCHAR2(90),
    PERSON VARCHAR2(10) NOT NULL,
    CONT_JOB VARCHAR2(90) NOT NULL,
    SOURCE VARCHAR2(8) NOT NULL,
    ADS VARCHAR2(8) NOT NULL,
    CONT VARCHAR2(8) NOT NULL,
    SRCPERSONID VARCHAR2(15),
    FIRSTNAME VARCHAR2(90),
    MIDDLENAME VARCHAR2(90),
    LASTNAME VARCHAR2(90),
    FULLNAME VARCHAR2(90),
    TITLE VARCHAR2(50),
    SALUTATION VARCHAR2(90),
    ) on commit delete rows;
    create index i_contact_1 on contacts(dob, soundex(hh_lastname ));
    create index i_contact_pk on contacts(id, person, cont_job, source, ads, cont);
    create index i_contact_2 on contacts(srcpersonid, source);

    Bug 3238525 - Upgrade from 9.0 can leave corruptdata for global temporary table indices
    ORA-600 [kftts2bz_many_files]
         Doc ID:      285592.1

  • How can i create table which in use

    Dear all,
    How can i create a index on table which have much dml any time?

    In 10g :
    The CREATE ONLINE waits for existing transactions to commit before it can proceed. Once it starts, it uses a log table (MV Log) to track subsequent changes (i.e. it allows concurrent DML once it has started). At the end of the operation, it encounters another wait if there are existing transactions as it has to sync changes from the MV Log to the index.
    Here's an explanation by Jonathan Lewis : Re: Alter Index Rebuild Online
    In 11g :
    There's an improvement in that only the transactions that were active at the instant when the CREATE .. ONLINE was issued are the ones it waits for. It does not have to wait on subsequent transactions.
    Here's an explanation by Richard Foote : http://richardfoote.wordpress.com/2008/02/11/index-create-and-rebuild-locking-improvements-in-11g-ch-ch-ch-changes/
    Hemant K Chitale

  • Cannot create Global Temporary Table

    Hi,
    i'm trying to create a Global Temporary Table. However I receive a missing or invalid options specified error.
    This should be one of the most simple ways to create a Global Temporary Table right?
    DECLARE GLOBAL TEMPORARY TABLE SESSION.T_MECHANIC_ALLOCATION
    START_TIME DATE
    ,SYSUR_AUTO_KEY NUMBER
    ,EPP_AUTO_KEY NUMBER
    ,STOP_TIME DATE
    ,WOK_AUTO_KEY NUMBER
    ON COMMIT DELETE ROWS

    No, you create a Global Temporary Table in the same way as any other table: beginning with the CREATE keyword:
    CREATE GLOBAL TEMPORARY TABLE T_MECHANIC_ALLOCATION
    START_TIME DATE
    ,SYSUR_AUTO_KEY NUMBER
    ,EPP_AUTO_KEY NUMBER
    ,STOP_TIME DATE
    ,WOK_AUTO_KEY NUMBER
    ON COMMIT DELETE ROWS

Maybe you are looking for

  • Spry collapsible panel fix for IE

    hey anyone out there knows how to fix the spry collapsible panels to work properly on IE ? Firefox is perfect  but  they appear and stay open even when clicked how could i make them appear closed and open only if clicked, close again when clicked to

  • Reg. cursor based delete! Little Urgent!

    Hi all, While accessing for a change now, i need to delete the values that came out of the cursor. For an Exting functionality: I am fetching few values by a cursor and i am starting a loop for executing few condtions based on the records available i

  • Database Data Out Of Date

    The site was upgraded from ZFD 3 to 4. The inventory scan was run overnight but the data shown in the database is not the most up to date. There are str files created in zenworks\inv\scandir. I've tried stopping and restaring Zenworks on the server.

  • Upgrade to 10.4.7 causes severe display flicker

    I am running a 15-inch MacBook Pro connected to a 23" cinema HD display. Since the upgrade to 10.4.7, the laptop screen starts to severely flicker after approximately 3-5 minute, rendering it unusable. Moving a window around (even on the 23") will ca

  • Knowledge management applications....

    Hi Friends, I am new to Knowledge management applications, can any one please provide the links.