如何向对象方法声明引用游标参数?
我对 PL/SQL 有点陌生,需要看起来有点像这样的东西:
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 );
基本上,我需要一个通用例程,它知道如何执行与表无关的操作,将特定于表的任务委托给派生类。
上述采用“引用光标”的对象方法无法编译 - 编译器表示“需要定义光标”。 因此,我当然已经尝试过“键入 generic_cursor 作为引用光标”,但无法编译它。
当我试图追踪将引用游标传递给对象方法的语法时,我几乎什么也没发现。 这让我觉得也许我正在尝试做一些愚蠢的事情。
我想做的事情有意义吗? 如果是这样,我错过了什么? 在哪里可以定义 generic_cursor 以便我可以将其用作对象方法参数类型?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦你解决了语法错误,你的代码就可以工作了。
当您是新手时,Oracle 文档很难理解。 我认为在您的情况下,您需要知道 面向对象的内容与常规 PL/SQL 信息。 每当您遇到困难时,您可能都需要检查两者。
Your code will work once you sort out the syntactical errors.
The Oracle documentation is pretty hard to understand when you're new. I think in your case you need to know that the Object_Oriented stuff is in a different book from the regular PL/SQL information. You will probably need to check both whenever you're stumped.