你需要使用PIPELINED
函数。下面的示例,最后链接到更多信息。
CREATE TABLE test_pipe (
id NUMBER,
name VARCHAR2(20),
salary NUMBER
);
INSERT INTO test_pipe VALUES (1, 'Smith', 5000);
INSERT INTO test_pipe VALUES (2, 'Brown', 8000);
INSERT INTO test_pipe VALUES (3, 'Bay', 10000);
COMMIT;
CREATE TYPE t_pipe_row_test AS OBJECT (
name VARCHAR2(20),
salary NUMBER
);
/
CREATE TYPE t_pipe_test_tab IS TABLE OF t_pipe_row_test;
/
CREATE OR REPLACE FUNCTION test_func_pipe(p_min_salary IN NUMBER)
RETURN t_pipe_test_tab
PIPELINED
AS
BEGIN
FOR v_rec IN (SELECT name, salary
FROM test_pipe
WHERE salary >= p_min_salary)
LOOP
PIPE ROW (t_pipe_row_test(v_rec.name, v_rec.salary));
END LOOP;
END;
/
SELECT * FROM TABLE(test_func_pipe(6000));
输出:
姓名 薪水
-------- ----------
棕色 8000
湾 10000
更多关于 Tim Hall 的流水线函数