I'm a little bit new to PL/SQL and need something that looks a bit like this:
create type base as object (
unused number,
member procedure p( c in ref cursor )
) not final;
create type child1 under base (
overriding member procedure p( c in ref cursor ) as
t table1%rowtype
begin
fetch c into t;
-- process table1 row
end;
);
create type child2 under base (
overriding member procedure p( c in ref cursor ) as
t table2%rowtype
begin
fetch c into t;
-- process table2 row
end;
);
procedure generic_handler( o in base, c in ref cursor ) as
begin
o.p( c );
end;
o1 child1 := child1(0)
o2 child2 := child2(0)
c ref cursor
open c for select * from table1;
generic_handler( o1, c );
open c for select * from table2;
generic_handler( o2, c );
Basically, I need a single generic routine that knows how to perform a table-independent action delegating table-specific tasks to a derived class.
The above object methods taking 'ref cursor's don't compile - compiler says 'cursor needs to be defined'. So of course I've tried 'type generic_cursor as ref cursor' all over the place but can't get it to compile.
I found pretty much nothing when trying to track down the syntax for passing ref cursors to object methods. And this made me think that perhaps I'm trying to do something stupid.
Does what I'm trying to do make sense? If so, what am I missing? Where can I define the generic_cursor so that I can use it as an object method parameter type?