3

Here's my application workflow.

I have a ref cursor that is populated with all my employees IDs..It's just an identification number really.

But now I want to fetch a lot of information for every employee...(as fetched form the ref cursor).It's not simply data, but a lot of computed,derived data too. The sort of derivation that's more easily done via cursors and procedures and so on....

For example, the sum of all the time intervals during which an employee was stationed in Department 78...(that could be just one of the columns for each employee).

So I think I could accomplish this with a really large (by large, I mean really difficult to maintain, difficult to understand, difficult to optimize, difficult to reuse, refactor..etc etc) SQL query, but that really isn't something I'd do unless as a real last resort.

So I'm trying to find ways to use all of PL/SQL's might to split this into as many separate units (perhaps functions or procedures) as possible so as to be able to handle this in a simple and elegant way...

I think that some way to merge datasets (ref cursors probably) would solve my problems... I've looked at some stuff on the internet until now and some things looked promising, namely pipelining... Although I'm not really sure that's what I need..

To sum up, what I think I need is some way to compose the resulting ref cursor(a really big table, one column for the ID and about 40 other columns, each with a specific bit of information about that ID's owner.),using many procedures, which I can then send back to my server-side app and deal with it. (Export to excel in that case.)

I'm at a loss really.. Hope someone with more experience can help me on this.

FA

Felipe
  • 11,557
  • 7
  • 56
  • 103
  • 1
    Seems like you could make use of a pipelined function which returns the data & other named/anonymous blocks to serve as helper functions to calculate the data. Maybe this will help? [Database: Pipelined Functions](http://stackoverflow.com/q/2889057) – Sathyajith Bhat Feb 17 '12 at 04:06

1 Answers1

1

I'm not sure if that is what you want, or how often do you need to run this thing
But since it sounds very heavy maybe you dont need the data up to date this second
If it's once a day or less, you can create a table with the employee ids,
and use seperate MERGE updates to calculate the different fields
Then the application can get the data from that table
You can have a job that calculates this every time you need updated data.
You can read about the merge command here wiki and specifically for oracle here oracle.
Since you use separate commands you can of course do it in different procedures if that is convenient.
for example:

begin
execute immediate 'truncate table temp_table';

insert into temp_table select emp_id from emps;

MERGE INTO temp_table a USING ( select name ) b on (a.emp_id = b.emp_id ) WHEN MATCHED THEN UPDATE SET a.name = b.name; ...

yael alfasi
  • 692
  • 1
  • 4
  • 13