1. create object (t_row )
CREATE TYPE t_row AS OBJECT (
id NUMBER,
name VARCHAR2(100)
);
2. create table type (t_tab ) using object created in step1
-- CREATE TYPE t_tab IS TABLE OF t_row;
3. CREATE FUNCTION fn() RETURN typ_created_above_in_2 PIPELINED and PIPE the ROWS
CREATE OR REPLACE FUNCTION get_students (p_rows IN NUMBER) RETURN t_tab PIPELINED AS
BEGIN
FOR i IN 1 .. p_rows LOOP
PIPE ROW(t_row(i, 'Student '||i));
END LOOP;
RETURN;
END;
P.S. - MUST use a blank RETURN call in the end
4. Test it.
SELECT *
FROM TABLE(get_students(10))
ORDER BY id DESC;
CREATE TYPE t_row AS OBJECT (
id NUMBER,
name VARCHAR2(100)
);
2. create table type (t_tab ) using object created in step1
-- CREATE TYPE t_tab IS TABLE OF t_row;
3. CREATE FUNCTION fn() RETURN typ_created_above_in_2 PIPELINED and PIPE the ROWS
CREATE OR REPLACE FUNCTION get_students (p_rows IN NUMBER) RETURN t_tab PIPELINED AS
BEGIN
FOR i IN 1 .. p_rows LOOP
PIPE ROW(t_row(i, 'Student '||i));
END LOOP;
RETURN;
END;
P.S. - MUST use a blank RETURN call in the end
4. Test it.
SELECT *
FROM TABLE(get_students(10))
ORDER BY id DESC;
No comments:
Post a Comment