Solved

Best way to populate smaller collections from one huge collection?

Posted on 2014-02-19
10
257 Views
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???

CODE BELOW:

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
 -- BASED ON VIEW
 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
 BEGIN
 
    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;
0
Comment
Question by:loginboy
[X]
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
10 Comments
 
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.
0
 

Author Comment

by:loginboy
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.
0
 
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.
0
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

by:loginboy
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?
0
 
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.
0
 

Author Comment

by:loginboy
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
  begin
    return(emp_obj_type(null,
                        null,
                        null));
  end initialize;
end;
/


create or replace type emp_obj_type_tbl IS TABLE OF emp_obj_type;

SET SERVEROUTPUT ON
declare
 v_emp_obj_rec         emp_obj_type := emp_obj_type.initialize();
 v_emp_obj_tbl         emp_obj_type_tbl := emp_obj_type_tbl();
begin

 for i in 1..3
 loop
   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.extend();
   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?
 */
 
end;
/
0
 
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:
given:
create table tab1(col1 char(1));
--with data, the 'sample data'
insert into tab1 values('a');
insert into tab1 values('1');
commit;

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

col1
------
1



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...
0
 
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?
0
 

Accepted Solution

by:
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)
0
 

Author Closing Comment

by:loginboy
ID: 39998521
Found solution outside of EE
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

636 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