我正在尝试创建一个接受值的pl / sql函数。游标在where子句中使用该值,该函数应返回游标的第一行。
这就是我想要的工作。
create or replace package pkg_test_slot as
cursor c_test_slotis
select * from (select person_uid, test.test, rownum r from test)
pivot(max(test) test_code for r in (1,2,3,4,5));
function f_test_getter (p_entity_uid number) return c_test_slot%rowtype;
end;
答案 0 :(得分:2)
像这样的东西
create or replace package body p_test is
function get_rows(pll_limit in number) return sys_refcursor is
lcur_rec sys_refcursor;
begin
open lcur_rec for
select rownum rw, dum
from (select 1 dum from dual group by cube(1, 2, 3, 4, 5))
where rownum < pll_limit;
return lcur_rec;
end get_rows;
procedure prc_get_data is
lcur sys_refcursor;
begin
lcur := get_rows(10);
end prc_get_data;
end p_test;
答案 1 :(得分:1)
您可以将F_TEST_GETTER
实现为:
CREATE OR REPLACE PACKAGE PKG_TEST_SLOT AS
CURSOR C_TEST_SLOT(pEUID IN NUMBER) IS
SELECT PERSON_UID, TEST.TEST, ROWNUM R
FROM TEST t
WHERE t.ENTITY_UID = pEUID;
FUNCTION F_TEST_GETTER (P_ENTITY_UID NUMBER)
RETURN PKG_TEST_SLOT.C_TEST_SLOT%ROWTYPE;
END PKT_TEST_SLOT;
CREATE OR REPLACE PACKAGE BODY PKG_TEST_SLOT AS
FUNCTION F_TEST_GETTER(P_ENTITY_UID NUMBER)
RETURN PKG_TEST_SLOT.C_TEST_SLOT%ROWTYPE
AS
aRow PKG_TEST_SLOT.C_TEST_SLOT%ROWTYPE;
BEGIN
OPEN C_TEST_SLOT(P_ENTITY_UID);
FETCH C_TEST_SLOT INTO aRow;
CLOSE C_TEST_SLOT;
RETURN aRow;
END PKG_TEST_SLOT;
END PKG_TEST_SLOT;
请注意,我已经简化了C_TEST_SLOT的定义,添加了参数,并显示了它在函数中的使用方式。希望这会给你一些想法。分享并享受。