Temporary tables

i am trying to create a temporary table in PL/SQL and want to insert rows.
create procedure temp
as
xsql varchar2(1000);
begin
vsql := 'create global temporary table t1 (n1 varchar2(50))';
execute immediate vsql;
insert into t1 values ('abc');
select * from t1;
end;
it does not allow me to compile and gives error ORA-00945: table or view does not exists

The following block might get created. As the table is created on the fly, (i.e is the table gets created and records inserted only when executing the procedure and not when the procedure is created), we cannot have the table name outside the variable.
Thanks,
Sriram.
create or replace procedure temp1
as
vsql varchar2(1000);
tbl_name varchar2(30) := 'T1';
v_ins varchar2(1000);
v_n1 varchar2(50);
v_sel varchar2(1000);
begin
vsql := 'create global temporary table t1 (n1 varchar2(50))';
execute immediate vsql;
v_ins := 'insert into'||tbl_name||'values (''abc'')';
execute immediate vsql;
v_sel := 'select n1 into v_n1 from t1';
execute immediate v_sel;
end;

Similar Messages

  • Temporary table within a package

    I'm not sure this is the best way to achieve it, but I'm trying to use a temporary table within my package, but I failed!
    In my package, my procedure do receive 5 different phone numbers (vTel1 to vTel5) and I need to order them, using data from a table. Also, if 2 of them are the same, I need only the one with the highest rank.
    Let say my TelOrder table look likes:
    Reason
    Tel1
    Tel2
    Tel3
    Tel4
    Tel5
    Reason1
    2
    3
    1
    5
    4
    Reason2
    1
    2
    null
    3
    4
    And I receive those variable
    vTel1='5141111111'
    vTel2=null
    vTel3='5143333333'
    vTel4='5141111111'
    vTel5='5145555555'
    vReason='Reason1'
    Using the Reason1, I need to be able to get the result looking like:
    RowNum
    Phone
    Order
    1
    5143333333
    1
    2
    5141111111
    2
    3
    5145555555
    4
    And I need this code to be apart from the procedure, cause many procedures will use the same code, and I don't want to abuse the ctrl+c, ctrl+v at each update.
    I've come close by using something like:
    EXECUTE IMMEDIATE '
         INSERT INTO Table
         SELECT Rownum as RN, Ordre, contact_info, Contact_info_type
         FROM
           (SELECT a.contact_info, a.ordre, contact_info_type FROM
             (SELECT contact_info,min(ordre) as Ordre FROM
               (SELECT Tel1 as Ordre, ''' || vTel1 || ''' as contact_info, 1 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
               UNION ALL
               SELECT Tel2 as Ordre, ''' || vTel2 || ''' as contact_info, 2 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
               UNION ALL
               SELECT Tel3 as Ordre, ''' || vTel3 || ''' as contact_info, 4 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
               UNION ALL
               SELECT Tel4 as Ordre, ''' || vTel4 || ''' as contact_info, 4 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
               UNION ALL
               SELECT Tel5 as Ordre, ''' || vTel5 || ''' as contact_info, 1 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
             WHERE Ordre is not null and contact_info is not null
             GROUP BY contact_info
             ) a
           JOIN
             (SELECT Tel1 as Ordre, ''' || vTel1 || ''' as contact_info, 1 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
             UNION ALL
             SELECT Tel2 as Ordre, ''' || vTel2 || ''' as contact_info, 2 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
             UNION ALL
             SELECT Tel3 as Ordre, ''' || vTel3 || ''' as contact_info, 4 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
             UNION ALL
             SELECT Tel4 as Ordre, ''' || vTel4 || ''' as contact_info, 4 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
             UNION ALL
             SELECT Tel5 as Ordre, ''' || vTel5 || ''' as contact_info, 1 as contact_info_type FROM TelOrder WHERE Reason=''' || vReason || '''
             ) b ON a.contact_info=b.contact_info AND a.ordre=b.ordre
           ORDER BY a.Ordre
    But when I try to remove this code and send it into another procedure/function, I can't make it work.
    PLEASE HELP!!!!  

    No Database to try it. Check at your own risk if this might work for you
    no version specified from your side, NOT TESTED from my side, so let's say we're even
    select row_number() over (order by the_order) "RowNum",
           the_val "Phone",
           the_order "Order"
      from (select v.the_val,t.the_order,
                   row_number() over (partition by v.the_val order by t.the_order) rn
              from (select reason,the_order,the_phone
                      from (select reason,tel1,tel2,tel3,tel4,tel5
                              from telorder
                             where reason = :the_reason
                    unpivot include nulls (the_order for the_phone in (tel1 as 'tel1',
                                                                       tel2 as 'tel2',
                                                                       tel3 as 'tel3',
                                                                       tel4 as 'tel4',
                                                                       tel5 as 'tel5'
                   ) t,
                   (select 'tel1' the_var,:v_tel1 the_val from dual union all
                    select 'tel2' the_var,:v_tel2 the_val from dual union all
                    select 'tel3' the_var,:v_tel3 the_val from dual union all
                    select 'tel4' the_var,:v_tel4 the_val from dual union all
                    select 'tel5' the_var,:v_tel5 the_val from dual
                   ) v
             where t.reason = :v_reason
               and t.the_phone = v.the_var
    where rn = 1
       and the_val is not null
    Regards
    Etbin

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

  • Can I get Date also from temporary table?

    --(1) get table ONLY
    create global temporary table cat1
    as select * from category;
    --(2) get table and data
    create table cat2 as select * from category;
    null

    Use Index

  • Report: sorting of data and temporary table sorting

    We have a report that runs a procedure, which inserts data into a temporary table using the supplied parameters. The report then selects data from this table.
    Previously the report has always displayed data in the same order in which it was inserted into the table, even though no sorting is specified by the report itself. I realize that the report itself ought to specify the sorting in order to guarantee it, but this has worked in the past.
    As part of an application/Oracle upgrade the report has been recompiled. Data is now displayed in a different order as before. However, each time we run it now, it IS the same (new) sorting. So it's still consistent, but consistent in a different way than before.
    Is there some way to go back to the old sorting (display in same order as inserted into table) - without having to re-code this (and all the other) reports in order to specify the sorting? We think that data is still inserted into the temporary table in the same order as before. We are using the same version of Crystal Reports.
    Edited by: user489847 on May 31, 2010 4:01 AM

    Crystal Reports.This is the Oracle Reports forum.
    Anyway, I have seen this in one of our applications too. Suddenly the ordering was different, because there was no explicit order by. There is never a guarantee of the ordering if you do not specify it.
    You should ask this in the database forum too, since this is not really Reports related.

  • Use of global temporary tables in Procedures

    Hi
    I am using global temporary tables in the procedures. Loading data in the same table through many procedures. I am fetching the data from the global temporary table in PRO-C by a cursor. Will this degrade performance?
    Please help me..
    Thanks in Advance...

    Will this degrade performance?That depends... in comparison to what?
    Loading data into temporary tables will generally be more efficient than loading data into permanent tables because Oracle needs to do less to protect this data since it is inherently transient. On the other hand, loading the data into a table in the first place tends to be more expensive than alternatives like using a single SQL statement, a pipelined table function, or an in memory collection.
    Justin

  • How to Use Temporary table on report builder

    Hi community!
    Well, i'm trying to build a temporary table based report in Oracle Report Builder. in "After Parameter Form Trigger" I've placed a stored procedure that populate a temporary table and I've based my report on it. The problem is Report shows no data. When i execute this procedure directly on database and i perform a select on my temporary table, it show all inserted data.
    I hope somebody can to help me because I tried many ways to build this report with my temporary table and always looks blank.

    Temporary tables are session specific.
    If particular session is closed then no data will be found on your temporary table in an another session.
    My suggestion is, on "After parameter form" trigger you directly populate the GTT without using procedure.
    Hope this will help.

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

  • Life time of data in a Global Temporary Table.

    Dear Friends,
    I have a global temporary table in which I insert some values via a backend package, when forms start up and accessing it via the same package when user performs some changes in it - storing the value and during exit saving it in the master table. My problem is the data is not accessible while processing. I'm using Oracle9i Enterprise Edition Release 9.2.0.1.0 database and Forms [32 Bit] Version 6.0.8.8.0. I also give you the script in using which I created the temporary table.
    CREATE GLOBAL TEMPORARY TABLE GTT_PRA
    A1 VARCHAR2(10 BYTE) NOT NULL,
    A2 VARCHAR2(15 BYTE) NOT NULL,
    A3 VARCHAR2(10 BYTE) NOT NULL
    ON COMMIT DELETE ROWS;
    Why is that so? Please help me.
    With Regards,
    Senthil .A. Perumal.

    Dear Arun,
    Thank you for your script. But I'm accessing a large table, so for each and every process, the table get populated and grows very large giving some space problem, that is why I'm deleting rows when commiting. I would appreciate your help.
    Dear Yogesh,
    From the same forms I'm calling the backend package - will that be a different session. Once I'm calling to populate the table and next time I'm calling to store the user modified data and finally calling to store the data to master table. I think all are in the same sessions. Please reply me.
    Thank you dear friends fr your immediate response. I would really appreciate it.
    Regards,
    Senthil .A. Perumal.

  • How to check the data in a temporary table

    Hi,
    A procedure inserting data into a temporary table , data exists in the table now. so, how to see the data from the temporary table. Is it possible to see from the sqlplus by selecting, right now i'm not getting any data. .thanks Bcj.

    If you are referring to Global Temporary Tables, then the only way to see the contents of the table are to select from the table while connected to the same session that inserted the data into the GTT.
    Please note however that there is not a 1 to 1 correspondence between sessions and users (shcemas). A user may be connected to 1 or more sessions, but it is only the session that inserted the records that will be able to view the records.

  • How can i create a temporary table in my report

    hi
    how to create temporary tables in reports
    please tell me detailed procedure with an example
    thanks in advance
    prasanth

    in before parameter form or before report trigger or in any triger where u want just pass u r query as..
    SRW.DO_SQL('CREATE TABLE MYTABLE....')
    hope it will solve your porb.
    Thanks

  • Is there a way to create "temporary" tables in SAP database?

    Hello,
    Is there a way to create temporary tables in ABAP?
    Here is our scenario:
    1. Invoke a custom RFC that creates a temporary table and returns the name of the table.
    2. Invoke another custom RFC and pass this table name as parameter. This RFC internally does some INNER JOIN with the temporary table.
    3. Invoke the third RFC to delete the temporary table.
    Note that the name of the table cannot be static. We have many users using our application simultaneously and connecting to the SAP server.
    I would appreciate it if you could point me in the right direction.
    Thank you in advance for your help.
    Peter

    I just ran into a similar issue.  While only calling the select statement 2 times, each time had so many entries in the 'for all entries' list, that the compiler converted this into about 700 calls to the select.  Now since the select joined three real tables on the database, the trace shows this one select as being the slowest item in this application.
    I think that happened because 'for all entries' gets converted to an 'IN' clause, and then the total number of characters in any SQL statement has an upper limit.   So the compiler must make the select statement over and over until it covers all entries in the 'for all entries' list.  Is that correct?
    Since every database I ever saw has the concept of db temporary tables, I have used db temp tables many times for this sort of thing.
    The ABAP compiler could determine that more than one IN statement will be need, then use an alternate: write all the FOR ALL ENTRIES to a db temp table, then join on the db temp table, then drop db temp table.  Since the compiler does this sort of thing, no application code needs change to get the speed boost.

  • ORA-00955 reports when I try to "create global temporary table" in windows

    Hi,
    When I try to run the sql in my oracle 9i server which is installed in a windows2000 machine,
    Create global temporary table test ...;
    For the first time, I can create table successfully.
    But I cannot access this table any more:
    drop table test;
    desc test;
    select * from test;
    In addition, if I try to create the table again, I got the error:
    ORA-00955: name is already used by an existing object
    While the same table can be created and dropped in another oracle9i server which is installed in Solaris 9 machine.
    So I suspect that this sould be a bug of window oracle server.
    Is there anyone who can confirm this?
    Or who can tell me how to report this bug to oracle?
    Thanks in advance.
    Please also refer the message at:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1046974576560
    If you search the text: "create global temporary table sess_event", you can see for the first time, the table is created successfully.
    But the ORA-00955 reports when the author try to create table for the second time.
    This problem is exactly the same as my problem.
    I have also made a search both in Google and in Oracle website and I cannot find any solution of it.

    Read      Metalink Note:68098.1 Subject:      Overview of Temporary Tables
    How did you difine the temporary tables? on commit delete rows are reserv rows?
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg03sch.htm#7794
    Jaffar
    Message was edited by:
    The Human Fly

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

  • How to purge data in a global temporary table from another session

    I've got a problem with vendor-delivered web-based software (jdbc) that periodically "hangs." When that happens, I have to kill the database session before retrying the process. This "workaround" does NOT clean up the temporary tablespace. Is there anyway (outside of bouncing the database) to truncate temporary tables regardless of sessionid? Thanks.

    In 8i the space used by temporary segments is not dropped in a temporary tablespace. The space is available for other queries or temporary tables. This avoids the costs of allocating and releasing space for temporary segments.

  • 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

Maybe you are looking for

  • Display picture in messages totally  pixelated when seeing it with yahoo messenger for windows

    Hello, I'm using messages to chat with my yahoo messenger account  at work and yahoo messenger for windows at home. When I log into Yahoo with messages, my yahoo display picture is updated automatically with the one I have choose in messages. My prob

  • UCCX and agent desktop +E.164

    Hello - we are running 10.0 UCCX and looking to see if +E.164 is supported.  The issue we have with this is that with agent desktop it does not allow the + sign in the extension field.  IS there a work around for this?

  • Cannot Backup or Sync

    First off I think it is ridiculous that Apple do not offer an online help support but instead you have to ring them up. Ever since the iTunes and iPod update I have had issues Syncing my iPod and backing it up, also since the iTunes update it keeps c

  • When KF value only provided at higher level and not at more detailed level

    Dear Experts I have a multiprovider consisting 2 DSOs: 1.  DSO for price. Eg.  Char-A__Char-sub1___Char-sub2___KF_PRICE AAAA__ AA11________AA22________$10 AAAA__AA11_________AA23_______ $17 As shown above,  AAAA is made up of 2 sub-items AA22 and AA2

  • Can't view simple JPG photo attachments emailed to me...

    Another really basic issue. My wife sends me a simple JPG in an email. I can't see the picture on the iPhone. It's visible in Mail on my desktop. iPhone just doesn't work (either under 2.01 or 2.0)