오라클 절차에서 커서을 반환해야 커서에 RECORD 유형이 포함되어야합니다. RECORD가 단순 할 때이 문제를 해결하는 방법을 알고 있지만 어떻게 해결할 수 있습니까? NESTED RECORDS?Oracle 프로 시저에서 NESTED RECORD 유형으로 채워진 커서를 반환하는 방법
-- create package with a RECORD type
create or replace package pkg as
-- a record contains only one simple attribute
type t_rec is RECORD (
simple_attr number
);
end;
/
-- create a testing procedure
-- it returns a cursor populated with pkg.t_rec records
create or replace procedure test_it(ret OUT SYS_REFCURSOR) is
type cur_t is ref cursor return pkg.t_rec;
cur cur_t;
begin
-- this is critical; it is easy to populate simple RECORD type,
-- because select result is mapped transparently to the RECORD elements
open cur for select 1 from dual;
ret := cur; -- assign the cursor to the OUT parameter
end;
/
-- and now test it
-- it will print one number (1) to the output
declare
refcur SYS_REFCURSOR;
r pkg.t_rec;
begin
-- call a procedure to initialize cursor
test_it(refcur);
-- print out cursor elements
loop
fetch refcur into r;
exit when refcur%notfound;
dbms_output.put_line(r.simple_attr);
end loop;
close refcur;
end;
/
당신이 저를 보여줄 수, 기록 t_rec 중첩 된 RECORD이 포함 된 경우이를 수행하는 방법은 :
간단한 레코드에 대한 코드의 작업 블록이있다?
는 folowing 방법으로 예를 수정 :
-- create package with a NESTED RECORD type
create or replace package pkg as
type t_rec_nested is RECORD (
nested_attr number
);
-- a record with NESTED RECORD
type t_rec is RECORD (
simple_attr number,
nested_rec t_rec_nested
);
end;
/
create or replace procedure test_it(ret OUT SYS_REFCURSOR) is
type cur_t is ref cursor return pkg.t_rec;
cur cur_t;
begin
-- how to populate a result?
open cur for ????
ret := cur;
end;
/
문제는 커서를 채우는 test_it 프로 시저를 수정하는 방법은? 나는 해결책을 찾기 위해 많은 시간을 보냈다. 나는 어떤 도움을 주셔서 감사하겠습니다.
예! 어떻게 그런 분명한 해결책을 놓칠 수 있는지 이해할 수 없습니다. 고맙습니다. – giorge