Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Best way to populate smaller collections from one huge collection?

Posted on 2014-02-19
Medium Priority
Last Modified: 2014-04-14
Best way to populate smaller collections (based on underlying tables) from one huge collection (based on View)?
1) Real time facts: Data volume is decent, 10K rows avg (may be 100K in 1 year), 1 view - 4 underlying tables
2) Is Associatve arrays best or nested table???


type my_emp_tbl IS TABLE OF emp%ROWTYPE index by pls_integer;
type my_dept_tbl IS TABLE OF dept%ROWTYPE index by pls_integer;
type my_loc_tbl IS TABLE OF loc%ROWTYPE index by pls_integer;

CREATE OR REPLACE emp_dept_loc_pkg IS
 type my_emp_dept_loc_tbl IS TABLE OF my_emp_dept_loc_view%ROWTYPE INDEX BY pls_integer;
 emp_dept_loc_procedure (in_emp_dept_loc_tbl IN my_emp_dept_loc_tbl);
END emp_dept_loc_pkg;

CREATE OR REPLACE emp_dept_loc_pkg BODY IS
 PROCEDURE emp_dept_loc_procedure (in_emp_dept_loc_tbl IN my_emp_dept_loc_tbl) IS
    1) Process each record from the input (in_emp_dept_loc_tbl) collection and populate each of the
       other (decalared in separate pacakges based on underlying tables of this view) collections EMP, DEPT, LOC????
 END emp_dept_loc_procedure;
END emp_dept_loc_pkg;
Question by:loginboy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39871895
I would probably not use local collections at all.

Have you tested them versus just selecting from the view and processing without storing the results in memory as a collection?

As far as your question goes, I would personally set up both methods as as tests and, well, test them both against my database/server setup.

Author Comment

ID: 39872056
Hi slightwv,

Thanks. Technically it's not fromt he view from the input collection has structure of view.

the frontend technology will pass that huge colelction as input. So can't go with direct from view to table. Need to use collections.

Please advice.
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39872088
So where does the view come into play?

Will you be loading the 'collection' into the view?  parsing it and loading it into the base tables? what?

If you can drive what data type the application passes in, have you considered passing in a CLOB as XML and loading tables from the XML?

I would probably go the XML route but the final decision will be based on your own specific situation and likely require individual testing.  No two systems are the same so no single solution works best across systems.

As I mentioned in the question you just closed:  Any final decision will have to be based on your individual testing.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 39872097
In case DB nested table object (though it won't be used as a column in any physical table) are created, is it possible to read from this DB nested table object in PLSQL code? If so How?  what would the syntax be like?
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39872115
I would need to know more about your system and objects.  Even then, it still comes down to you needing to test variations on your specific system.

As for specific code examples that could not be found with an Internet search, we would need a test case that included objects, sample data and expected results.

That way, we could set it up on our test systems to make sure everything works the way you want it to work.

Author Comment

ID: 39872189
Here are the test objects, sample data, expected results....
Questions below in comments, Please help

create or replace type emp_obj_type as object
( ID     number,  
  NAME     varchar2(100),
  ROLE     varchar2(100),
  static function initialize return emp_obj_type

create or replace type body emp_obj_type as
  static function initialize return emp_obj_type is
  end initialize;

create or replace type emp_obj_type_tbl IS TABLE OF emp_obj_type;

 v_emp_obj_rec         emp_obj_type := emp_obj_type.initialize();
 v_emp_obj_tbl         emp_obj_type_tbl := emp_obj_type_tbl();

 for i in 1..3
   v_emp_obj_rec.ID    :=  i;
   v_emp_obj_rec.NAME  := 'ABC - ' || i;
   v_emp_obj_rec.ROLE  := 'ROLE of ABC - ' || i;
   v_emp_obj_tbl(v_emp_obj_tbl.last) := v_emp_obj_rec;
 end loop;
 dbms_output.put_line('Count of nested table - '||v_emp_obj_tbl.count());
 1) How to I read (right here) the data from this nested table object?
 2) Don''t want to use Loops
 3) Can I do direct SELECT?  
 4) CAST, COLLECT, MULTISET? Keywords will be helpful?
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39872224
>>Here are the test objects, sample data, expected results....

Sorry but not even close.

I see no actual data and no desired results.

What I'm looking for is:
create table tab1(col1 char(1));
--with data, the 'sample data'
insert into tab1 values('a');
insert into tab1 values('1');

I need:
-- the expected results:  Anything that is a number.


I need to be able to create my own objects from what you provide so I can produce the results you post as expected.

What is better "A" or "B" isn't a good question because of what I posted above:  Every database/system is different.  What is 'best' for one may not be 'best' or others.

Only by trial and error can you make that decision.  We can 'suggest' but only once we can test...
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39872234
Here is what I understand:

You have some application written in some language that will pass some data in some format to your database.

You want to know what the 'best' way to take that data and do something with it.

Now do you see where we need more information?

Accepted Solution

loginboy earned 0 total points
ID: 39989933
Worked with using the combo of TABLE and CAST functions

TABLE(CAST(variable_object_type AS object_type)

Author Closing Comment

ID: 39998521
Found solution outside of EE

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question