ref cursor 매개 변수를 객체 메소드에 선언하는 방법은 무엇입니까?
-
13-09-2019 - |
문제
나는 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 );
기본적으로 테이블 독자적인 작업을 파생 클래스에 위임하는 테이블 독립적 인 액션을 수행하는 방법을 알고있는 단일 일반 루틴이 필요합니다.
위의 객체 메소드는 'Ref Cursor's Do n't Compile -Compiler를 '커서를 정의해야'라고 말합니다. 물론 나는 'generic_cursor를 ref cursor로 ref cursor'로 시도했지만 그것을 컴파일 할 수는 없습니다.
나는 거의 많이 발견했다 아무것도 아님 Ref 커서를 객체 방법으로 전달하기위한 구문을 추적하려고 할 때. 그리고 이것은 아마도 내가 어리석은 짓을하려고한다고 생각하게 만들었습니다.
내가하려는 일이 이해가 되나요? 그렇다면 내가 무엇을 놓치고 있습니까? 객체 메소드 매개 변수 유형으로 사용할 수 있도록 generic_cursor를 어디에서 정의 할 수 있습니까?
해결책
구문 오류를 정리하면 코드가 작동합니다.
SQL> create or replace type base as object
2 ( unused number
3 , member procedure p( c in sys_refcursor )
4 )
5 not final;
6 /
Type created.
SQL>
SQL> create or replace type child1 under base (
2 overriding member procedure p( c in sys_refcursor )
3 );
4 /
Type created.
SQL> create or replace type body child1 as
2 overriding member procedure p( c in sys_refcursor )
3 as
4 t dept%rowtype;
5 begin
6 loop
7 fetch c into t;
8 exit when c%notfound;
9 dbms_output.put_line('dname='||t.dname);
10 end loop;
11 end;
12 end;
13 /
Type body created.
SQL>
SQL> create or replace type child2 under base (
2 overriding member procedure p( c in sys_refcursor )
3 );
4 /
Type created.
SQL> create or replace type body child2 as
2 overriding member procedure p( c in sys_refcursor )
3 as
4 t emp%rowtype;
5 begin
6 loop
7 fetch c into t;
8 exit when c%notfound;
9 dbms_output.put_line('ename='||t.ename);
10 end loop;
11 end;
12 end;
13 /
Type body created.
SQL>
SQL>
SQL> create or replace procedure generic_handler
2 ( o in out base, c in sys_refcursor )
3 as
4 begin
5 o.p( c );
6 end;
7 /
Procedure created.
SQL>
SQL> set serveroutput on size unlimited
SQL>
SQL> declare
2 o1 child1 := child1(0);
3 o2 child2 := child2(0);
4 rc sys_refcursor;
5 begin
6 open rc for select * from dept where deptno = 10;
7 o1.p(rc);
8 open rc for select * from emp where deptno = 10;
9 o2.p(rc);
10 end;
11 /
dname=ACCOUNTING
ename=BOEHMER
ename=SCHNEIDER
ename=KISHORE
PL/SQL procedure successfully completed.
SQL>
Oracle Documentation은 새로운 시점을 이해하기가 매우 어렵습니다. 나는 당신의 경우 당신은 Object_oriented 물건 다른 책과 다른 책에 있습니다 일반 PL/SQL 정보. 당신은 당신이 그루터기 될 때마다 두 가지를 모두 확인해야 할 것입니다.
제휴하지 않습니다 StackOverflow