package
CREATE OR REPLACE PACKAGE poly_pkg AS
FUNCTION describe (p_tbl IN OUT DBMS_TF.TABLE_T )
RETURN DBMS_TF.DESCRIBE_T;
END;
Package created.
package body
CREATE OR REPLACE PACKAGE BODY poly_pkg AS
FUNCTION describe (p_tbl IN OUT DBMS_TF.TABLE_T )
RETURN DBMS_TF.DESCRIBE_T AS
BEGIN
-- what schema is the table from?
DBMS_OUTPUT.PUT_LINE('Table Schema ' ||
p_tbl.schema_name);
-- what package is being run?
DBMS_OUTPUT.PUT_LINE('Table Package ' ||
p_tbl.package_name);
-- What PTF is being run?
DBMS_OUTPUT.PUT_LINE('Table PTF ' ||
p_tbl.ptf_name);
-- the column array in the DBMS_TF_TABLE_T
-- structure contains details of each column
FOR counter IN 1..p_tbl.column.count LOOP
DBMS_OUTPUT.PUT_LINE('Column ' || counter);
-- output the column name, the length of the
-- column name, the maximum value length allowed
-- and the data type of the column
DBMS_OUTPUT.PUT_LINE('- Name ' ||
p_tbl.column(counter).description.name);
DBMS_OUTPUT.PUT_LINE('- Name Len ' ||
p_tbl.column(counter).description.name_len);
DBMS_OUTPUT.PUT_LINE('- Max Len ' ||
p_tbl.column(counter).description.max_len);
DBMS_OUTPUT.PUT_LINE('- Datatype ' ||
p_tbl.column(counter).description.type);
END LOOP;
RETURN NULL;
END;
END;
Package Body created.
function
CREATE OR REPLACE FUNCTION poly_func(p_tbl IN TABLE)
RETURN TABLE PIPELINED
ROW POLYMORPHIC USING poly_pkg;
Function created.
demo table
CREATE TABLE table1
( col1 NUMBER,
col2 NUMBER )
Table created.
demo data
INSERT INTO table1
VALUES(19,99)
1 row(s) inserted.
demo query
SELECT *
FROM poly_func(table1)
COL1 | COL2 |
---|---|
19 | 99 |