Solved

Best way to populate smaller collections from one huge collection?

Posted on 2014-02-19
10
251 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
  • 5
  • 5
10 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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
Comment Utility
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 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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
 

Author Comment

by:loginboy
Comment Utility
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 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:loginboy
Comment Utility
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 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>>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 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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
Comment Utility
Worked with using the combo of TABLE and CAST functions

TABLE(CAST(variable_object_type AS object_type)
0
 

Author Closing Comment

by:loginboy
Comment Utility
Found solution outside of EE
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now