您可以使用管道功能来实现这一点。
-- drop type t_actor_tab;
-- drop type t_actor_obj;
-- drop function get_actor_ptf;
-- drop table ACTOR;
-- drop table info;
CREATE TABLE ACTOR(ID NUMBER, SAL NUMBER, BONUS NUMBER);
INSERT INTO ACTOR(ID, SAL, BONUS) VALUES(1, 1200, 120);
INSERT INTO ACTOR(ID, SAL, BONUS) VALUES(2, 1300, 240);
INSERT INTO ACTOR(ID, SAL, BONUS) VALUES(3, 1500, 120);
CREATE TABLE INFO(ID NUMBER, NAME VARCHAR2(30), SURNAME VARCHAR2(30));
INSERT INTO INFO(ID, NAME, SURNAME) VALUES(1, 'ABC', 'abc');
INSERT INTO INFO(ID, NAME, SURNAME) VALUES(2, 'xyz', 'xyz');
INSERT INTO INFO(ID, NAME, SURNAME) VALUES(3, 'MNO', 'mno');
CREATE TYPE t_actor_obj AS OBJECT (
id NUMBER
,sal NUMBER
,bonus NUMBER
,final_paycheck NUMBER
);
CREATE TYPE t_actor_tab IS TABLE OF t_actor_obj;
CREATE OR REPLACE FUNCTION get_actor_ptf
RETURN t_actor_tab PIPELINED AS
CURSOR get_details_cur
IS
SELECT a.id
,a.sal
,a.bonus
,(a.sal+a.bonus) final_paycheck
From actor a
where EXISTS(SELECT 1 FROM info i WHERE i.id = a.id);
v_details_row get_details_cur%ROWTYPE;
BEGIN
OPEN get_details_cur;
LOOP
FETCH get_details_cur INTO v_details_row;
EXIT WHEN get_details_cur%NOTFOUND;
PIPE ROW(t_actor_obj (v_details_row.id,v_details_row.sal,v_details_row.bonus,v_details_row.final_paycheck));
END LOOP;
CLOSE get_details_cur;
RETURN;
END;
/
SELECT * FROM TABLE(get_actor_ptf);
ID SAL BONUS FINAL_PAYCHECK
---------- ---------- ---------- --------------
1 1200 120 1320
2 1300 240 1540
3 1500 120 1620