Collections or Temporary tables?

I am trying to put together a wizard to collect data. These are employee timecards and consist of a master table and about 5 detail tables. I can successfully collect the master information into a collection, but I'm trying to figure out how to collect the detail information, as there may be information for each of the detail tables or not. The APEX.ITEM stuff would be very useful, but it seems to work better with information that is already present and this is all strictly data input (I'd like to start with 5 blank rows). The key is that I don't want to commit the data to the database until the user completes the wizard.
I have toyed with the idea of temp tables and maintaining the information using the session variable, but it seems like APEX already does this and I hate to create unnecessary load. Can anyone suggest an optimal method?

Although i am not that famliar with the apex collection functionality, i would recommened using this in your situation. Collection are automatically handled by apex per session, which is it's great advantage upon temp.tables. tables are not bound to the session of a user, and will be viewable/editable by all user logged in into the application.
As i mentioned, it is still on my to-do list for detail research of the functionality. but i have found some relevant blogpost about collections here => http://iadvise.blogspot.com/search/label/Collections
maybe it is of some help,
Simon

Similar Messages

  • 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

  • Global temporary table in PL/SQL called from APEX page

    I have a global temporary table in a PL/SQL procedure that is called from an APEX page.
    The global temp table is populated with data as the procedure runs and then at the end of the procedure I do a create_collection_from_query_b to populate a collection with the data from the temp table. (I do this b/c it is much faster than creating the collection and doing an add_member for each row.)
    The problem is that there are no commits in my procedure but I cannot get the bulk insert to work unless I define the temp table as on commit preserve rows.
    Can anyone shed any light on this issue.
    Thanks,
    Andrew

    alamantia wrote:
    My PL/SQL procedure is called from an after submit page process. Does that imply that there is a commit happening after that process is successful?Ultimately, yes.
    If the process calls the PL/SQL procedure and the temp table is in the procedure, wouldn't the commit fire after all the PL/SQL code is complete which would be after the bulk insert from the temp table to my collection?Yes, but at any point in the procedure containing code like
    :APEX_ITEM := ...or
    select ... into :APEX_ITEM from ...or
    my_procedure(p_in => ..., p_out => :APEX_ITEM, ...);or
    apex_util.set_session_state(...);then APEX will commit whilst maintaining session state.
    If you don't have any of these events in the procedure, then test to see if the commit is occurring in <tt>apex_collection.create_collection_from_query_b</tt> prior to creation of the collection.

  • Temporary table in a pl/SQL block

    Hi all. I am in the process of learning PL/SQL and right now I focusing on Temporary Tables & PL/SQL blocks. without going into great detail I have created a cursor for loop that will retrive records from a table based on my criteria. I now need to insert this information into a temporary table. I am somewhat familiar on the usage of a temporary table by itself but I am confused by its usage in the PL/SQL block itself. For example, does it need to be declared?

    pl/SQl block or PL/SQl table(associate array) ?
    this example will help, if i got is correct
    SQL> declare
      2  cur_emp sys_refcursor;
      3  type t_obj is record( empno number, ename varchar2(25));
      4  type t_tab is table of t_obj index by binary_integer;
      5  tt t_tab;
      6  begin
      7   open cur_emp for
      8    select empno,ename from emp where deptno=10;
      9     loop
    10      fetch cur_emp BULK collect into tt;
    11      exit when cur_emp%notfound;
    12     end loop;
    13     for i in 1..tt.count loop
    14        dbms_output.put_line('empno :' ||tt(i).empno||'     ename  :'||tt(i).ename);
    15     end loop;
    16   end;
    17  /
    empno :7782     ename  :CLARK
    empno :7839     ename  :KING
    empno :7934     ename  :MI_LL_ER
    PL/SQL procedure successfully completed.

  • Problem with temporary table refresh

    Hi,
    I running a process before validation on a page to populate a temporary table when I click a button.
    On the following page I've built a shuttle on the temporary table. Not the most elegant solution, but the shuttle LOV box wouldn't process the oracle text commands in the SQL.
    I'm not getting any error, but I have an unusual problem
    It takes two passes for the data to be replaced. i.e I enter 'ABCD' in the filter and it returns data with 'ABCD'
    If I return to the page and change the filter to 'EFGH' I still get 'ABCD'. I return to the page and click the button again and I get 'EFGH' results
    I've checked the data in the temporay table and that is updating in line with the problem.
    I've looked at the debug and that seems fine (i.e I can see the changed filter value), I've tried moving the truncate to a different process, that didn't help.
    I've run it in SQL developer and it seems to work fine.
    I've included the code below, but I can't see a problem with it.
    Can anybody help?
    begin
    EXECUTE IMMEDIATE('TRUNCATE TABLE temp_cat');
    commit;
    if length(:P26_ADD_FILTER) > 0 then
    insert into temp_cat (core_cat_id, core_cat_code, core_cat_desc)
    select core_cat_id,core_cat_code,core_cat_desc from core_cat where CONTAINS (core_cat_desc, '
    <query>
    <textquery lang="ENGLISH" grammar="CONTEXT">&P26_ADD_FILTER.
    <progression>
    <seq><rewrite>transform((TOKENS, "{", "}", " "))</rewrite></seq>
    <seq><rewrite>transform((TOKENS, "{", "}", " ; "))</rewrite></seq>
    <seq><rewrite>transform((TOKENS, "{", "}", "AND"))</rewrite></seq>
    <seq><rewrite>transform((TOKENS, "{", "}", "ACCUM"))</rewrite></seq>
    </progression>
    </textquery>
    <score datatype="INTEGER" algorithm="COUNT"/>
    </query>')>0 and core_cat_id not in (select pipe_project_cat.core_cat_id from pipe_project_cat where txtpamref = :p26_pamref);
    else
    insert into temp_cat (core_cat_id, core_cat_code, core_cat_desc)
    select core_cat_id,core_cat_code,core_cat_desc from core_cat where
    core_cat_id not in (select pipe_project_cat.core_cat_id from pipe_project_cat where txtpamref = :p26_pamref);
    end if;
    end;

    Hi,
    Apex does not work well with temporary tables as you cannot guarantee which session from the pool will be used to serve each page.
    In your case, it looks like the second page is using temporary data from the wrong session.
    Have you considered using Apex Collections instead?
    Luis

  • Does Global Temporary Table help in performance?

    I have a large database table that is growing daily. The application I have has a page for the past day data and another for some chosen period of time. Since I'm looking at a very large amount of data for each page (~100k rows) and having charts based on time, I have performance issues. I tried collections for each of these and found out that it is making everything slower and I think because the collection is large and it is not indexed.
    Since I don't need the data to be maintained for the session and in fact for each time that I submit a page I need to get the updated data at least for the past day page, I wonder if Global Temporary Table is a good solution for me.
    The only reason I want to store the data in a table is to avoid running similar queries for different charts and reports. Is this a valid reason at all?
    If this is a good solution, can someone give me a hint on how to do this?
    Any help is appreciated.

    It all depends on how efficient your query is. You can have a billion row table and still get a fraction of a second response if the data is indexed, and the number of data blocks to be visited to retrieve the data is small. It's all about reducing the number of I/Os to find and retrieve your data with the query. Many aspects of the data, stats, table/index structure etc can influence the efficiency of your query. The SQL forum would be a better place to get into the query tuning, but if this test is fast, you can probably focus elsewhere for now. It will resolve your full resultset, and then just do a count of the result (to avoid sending 100k rows back to the client). We are trying to get an idea of how long it takes to resolve your resultset. Using litterals rather than item names in your sql should be fine for this test. Avoid using V() around item names in your SQL.
    select count(*) from ( <your-query-goes-here> );

  • Insert into temporary table

    I migrate procedures MS SQL Server to Oracle.
    In MS SQL SSERVER the use of instructions INSERT with procedure results which are in storage or dynamic instructions EXECUTE in place of VALUES clause is permissible. This construction is similar to INSERT/SELECT but we have to do with EXEC instead of SELECT. The part of EXEC should include exactly one resulted collection about the equivalent types to the types of table columns. In case of the stored procedure, we can pass on proper parameters, use the form of EXEC('string') and even call up wideranging procedures or remote control procedures from different servers. Calling up remote control procedures from different server, which place data in temporary table, and later realizing join with obtainable data, we can construct diffuse joins.
    For example. I want insert results stored procedures sp_configure, proc_obj in temporary table.
    1)INSERT #konfig
    exec sp_configure.
    2)
    CREATE PROCEDURE proc_test
    @Object_ID int,
    AS
    SET XACT_ABORT ON
    BEGIN TRAN
    CREATE TABLE #testObjects ( Object_ID int NOT NULL )
    INSERT
    #testObjects
    EXEC
    proc_obj @Object_ID,3,1
    COMMIT TRAN
    RETURN(0)
    go
    I don't know how migrate for example code to Oracle? Please examples in pl/sql.
    Best regards.

    Hi Elena,
    Patryk is you :) ?
    http://www.orafaq.com/forum/t/46956/67658/
    Rgds.

  • 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

  • Bulk collection PL/SQL table

    Hi all,
    10g version 10.2.0.1
    What approach can I take to accomplish the following.
    I need to build a collection based on the result set of two SQL statements within a loop.
    Example:
    FUNCTION( get_info )IS
    RETURN retrieval_pkg_public_ty
    PIPELINED
    TYPE ret_tab IS TABLE OF ret_rec;
    FOR i IN 1 .. 2
    LOOP
    SELECT...
    BULK COLLECT into ret_tbl
    FROM(SELECT...
    FROM(SELECT..
    quite a large SQL statement...
    WHERE
    x = parameter_value, --parameter changes on based on i values
    y = parameter_value, --parameter changes on based on i values
    END LOOP;
    FOR i IN ret_tbl.FIRST..ret_tbl.LAST
    LOOP
    PIPE ROW...
    END LOOP;
    I can use a global temporary table to hold the results of each loop and them select from gtt, however I would prefer to use a table function.
    thanks
    Mark

    user1602736 wrote:
    Currently, I have a procedure that is called within a package that returns a SYS_REFCURSOR.
    Current code in procedure is
    FOR i IN 1..2
    LOOP
    INSERt INTO gtt
    END LOOP;Why not simply populate the GTT using an INSERT INTO gtt SELECT ... FROM source WHERE .. ?
    I wanted to avoid creating a gtt to accomplish above.Why? What problems with this GTT approach do you think there are?
    The cursor only returns around 50 records. The record has around 20 data fieldsRemember that if you store this as a PL/SQL collection (there's no such thing as PL "+table+"), this collection resides in expensive private process memory (the PGA). If there a 100 sessions using this code, then there will be a 100 copies of this collection.
    On the other hand, a GTT does not reside in expensive private memory. And it can scale to a 1000 rows in future, without affecting performance (remember that GTTs can be indexed - collections not). For a collection, you will pay an excessive price in memory for keeping that 1000 rows in the PGA.
    GTTs are not a bad thing. Collections are not a bad thing. They are tools for addressing specific problems. Your task is to select the right tool for the job. Caching SQL row data in a PL/SQL collection is almost never the right tool for the job, as it requires private process memory and uses a very simplistic data structure (does not support indexes and so on).

  • Scalability issue with global temporary table.

    Hi All,
    Does create global temporary table would lock data disctionary like create table? if yes would not it be a scalable issue with multi user environment?
    Thanks and Regards,
    Rudra

    Billy  Verreynne  wrote:
    acadet wrote:
    am I correct in interpreting your response that we should be using GTT's in favour of bulk operations and collections and in memory operations? No. I said collections cannot scale. This means due to the fact that collections reside in expensive PGA memory, you cannot stuff large data volumes into them. Thus they do not make an ideal storage bin for temporary data (e.g. data loaded from file or a web service). GTTs otoh do not suffer from the same restrictions, can be indexed and offer vastly better scalability and so on.
    Multiple passes are often needed using such a data structure. Or filtering to find specific data. As a GTT is a SQL native, it offers a lot more flexibility and performance in this regard.
    And this makes sense - as where do we put out persistent data? Also in tables, but ones of a persistent and not temporary kind like a GTT.
    Collections are pretty useful - but limited in size and capability.
    Rudra states:
    I want to pull out few metrices from differnt tables and processing itIf this can't be achieved in a SQL statement, unless Rudra is a master of understatement then I would see GTT's as a waste of IO and programming effort. I agree.
    My comments however were about choices for a temporary data storage bin in PL/SQL.I agree with your general comments regarding temporary storage bins in Oracle, but to say that collections don't scale is putting to narrow a definition on scaling. True, collections can be resource intensive in terms of memory and CPU requirements, but their persistence will generally be much shorter than other types of temporary storage. Given the right characteristics, collections will scale and given the wrong characteristics GTT's wont scale.
    As you say it is all about choice. Getting back to the theme of this thread though, the original poster should be made aware that well designed and well coded applications are most likely to scale. Creating tables on the fly is generally considered bad practice and letting the database do what it does best, join tables in queries at the SQL level is considered good practice. The rest lies somewhere in between and knowing when to do which is why we get paid the big bucks (not). ;-)
    Regards
    Andre

  • Best to use in terms of tuning Global Temporary table or PLSQL Table type

    Hi All,
    which one is best to use in terms of tuning Global Temporary table or PLSQL table type?
    Thanks in Advance.
    Regards
    Deepika

    user8828028 wrote:
    which one is best to use in terms of tuning Global Temporary table or PLSQL table type?The answer to which one is better depends on the requirements - and an informed decision as to which one to use to address those requirements.
    Thus it is important to understand how these work. They are nothing alike.
    PL/SQL collections reside in the PGA. Can only be used in SQL via binding. Cannot be indexed. Temp tables on the other hand does not use expensive PGA. Does not need to be bind in SQL. Can be indexed. Etc.
    Sure, a (surgical) saw and scalpel are both used on the operating table - but for very different purposes.

  • Stored procedure return datatable or temporary table

    hi again everybody
    i just want to ask can stored procedure or function return a datatable or a temporary table that i want to fill later
    the problem is i want to make a stored procedure that make research for the client with many option and with this selected option the procedure execute the right request from
    different table and i just return the result in the datatable or the temporary table ????
    help ^^ and thank's

    >
    so i want make the client choose options for search and after that the programme interrogate my DB according to his options
    so the solution i want it ,i hope it's optimised cuz i dn't want to use much view or cursor so when i interrogate the BD i put the result into temporary table
    >
    Well that is a start at a better explanation though you still seem focused on the solution you want instead of the result you want. It shouldn't matter to you if a view or cursor is used if you get the result quickly. Besides all queries use cursors to get their results whether you explicitly define a cursor or not.
    The usual choices given to users for any particular search do not include which table or view to use. You would normally let the user select the filtering to be done.
    The columns and datatypes in the result set are usually fixed and are not provided dynamically. That is you wouldn't let user1 select 5 columns from tableA and user2 select 7 different ones. The reason is the the client software used to display the result set to the user needs to know how many columns it has to deal with and what the datatypes are.
    Only software like sql developer, toad or similar creates generic data grids with different columns and datatypes.
    >
    and that so the other thing i want is : can stored procedure or function return a datatable
    >
    As Justin said a pipelined function can return a result set but, like I just said above, it generally returns the same number of columns and the same datatypes every time it is called. A procedure can return a REF CURSOR that the client software can use to obtain the rows of the result set or the procedure could return an Oracle collection.
    But procedures/functions don't return actual tables. Returning a small collection is as close to that as you get.

  • How to call variable which name is stored in a temporary table...

    Hi there!
    Got a simple (?) question. I want to make an allocation like that:
    n#.temp_z1  := temp#; with the only Problem that the name of the variable is stored in another variable or a temporary table:
    temp#(1) := temp_z1; at the moment I have absolutly no idea how to resolve this Problem =( Need something like that (which don't work):
    n#.temp#(1)  := temp#; anybody there who could help me? Thanks in advance

    I think with dynamic SQL it won't work. Isn't there any solution just to handle this simple problem? =(
    ok, some more details to my Program:
    I have a table named "NN2_input" which will be filled dynamically. For the filling, a start and a finish number are given, and for every number between this, 3 columns will be created. Looks like that:
    min = 3; max = 5;
    => Columns:
    Z3_Gas, Z3_Dauer, Z3_Temp, Z4_Gas, Z4_Dauer, Z4_Temp, Z5_Gas, Z5_Dauer, Z5_Temp
    after the structure of the table is given, it should be filled. To see which columns are given, I select them in a temporary table:
    CREATE OR REPLACE PROCEDURE nn2_input_filling is
       type tab is table of VARCHAR2(15);
       gas#    tab;
       dauer#  tab;
       out#    tab;    
    BEGIN
       SELECT column_name BULK COLLECT INTO dauer# FROM sys.user_tab_columns
         WHERE table_name = 'NN2_INPUT' AND SubStr(column_name,4,5) = 'DAUER' ORDER BY column_name;
       SELECT column_name BULK COLLECT INTO gas# FROM sys.user_tab_columns
         WHERE table_name = 'NN2_INPUT' AND SubStr(column_name,4,3) = 'GAS' ORDER BY column_name;
       SELECT column_name BULK COLLECT INTO out# FROM sys.user_tab_columns -- gibt auch ein Z7_OUT2 zurück o.O
         WHERE table_name = 'NN2_INPUT' AND SubStr(column_name,4,3) = 'OUT' ORDER BY column_name;
    END;to fill this table, I must assign each field with this value. And that's where my Problem occurs...
    so I know all of the columns except the Numbers...

  • Temporary Tables in APEX

    Hello All,
    How can a user refresh a temporary table using APEX. I created 2 temp tables. How can I be sure that the temp tables have been updated when the user runs the report. Is there a button or procedure that I need to create to refresh the temp tables?

    Hello,
    I'd advise using temporary tables in APEX, since you cannot guarantee you will get the same database session within the mod_plsq session pool (or dbms_epg if you're using 11g or XE).
    Instead you will probably want to use a collection, there are details about collections in the documentation available here -
    http://download.oracle.com/docs/cd/B32472_01/doc/appdev.300/b32471/advnc.htm#BABFFJJJ
    Hope this helps,
    John.
    http://jes.blogs.shellprompt.net

  • Collection x temp table - what is the best title?

    In which of the structures bellow the performance is better? In the first, I use a collection with forall. In the second, I use a temp table with for loop.
    Consider the data to be the same in both the collection and the temp table.
    case 1 - collection:
    DECLARE
    TYPE NumList IS VARRAY(10000) OF NUMBER;
    depts NumList := NumList(10, 30, 70 ... 10000); -- department numbers
    BEGIN
    FORALL i IN depts.FIRST..depts.LAST
    DELETE FROM emp WHERE deptno = depts(i);
    END;
    case 2 - temp table:
    -- temp table
    create global temporary table depts
    num number
    -- inserts
    insert into depts (num) values (10);
    insert into depts (num) values (30);
    insert into depts (num) values (10000);
    -- code
    BEGIN
    FOR i IN (select num from depts) LOOP
    DELETE FROM emp WHERE deptno = i.num;
    END LOOP;
    END;

    Do you need loop in Case 2?
    Wouldn't this do?
    DELETE FROM emp WHERE deptno IN (select num from depts);Check this Collections vs table for discussion on similar topic

Maybe you are looking for