package
CREATE OR REPLACE PACKAGE poly_pkg AS
FUNCTION describe (p_tbl IN OUT DBMS_TF.TABLE_T )
RETURN DBMS_TF.DESCRIBE_T;
PROCEDURE fetch_rows;
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
v_new_col DBMS_TF.COLUMN_METADATA_T;
v_new_cols DBMS_TF.COLUMNS_NEW_T;
BEGIN
-- hide all columns selected
FOR counter IN 1..p_tbl.column.count LOOP
p_tbl.column(counter).pass_through := FALSE;
END LOOP;
-- add the rickroll column
v_new_col := DBMS_TF.COLUMN_METADATA_T(
name => 'RICKROLL' );
v_new_cols := DBMS_TF.COLUMNS_NEW_T( 1 => v_new_col);
RETURN DBMS_TF.DESCRIBE_T ( new_columns => v_new_cols,
row_replication => true);
END;
PROCEDURE fetch_rows IS
l_row_set DBMS_TF.row_set_t;
l_new_col DBMS_TF.tab_varchar2_t;
l_row_count PLS_INTEGER;
BEGIN
-- DUAL has one record but we need 6
DBMS_TF.ROW_REPLICATION(replication_factor => 6);
DBMS_TF.get_row_set(l_row_set, row_count => l_row_count);
-- Bring on those heartfelt lyrics!
l_new_col(1) := 'Never gonna give you up';
l_new_col(2) := 'Never gonna let you down';
l_new_col(3) := 'Never gonna run around and desert you';
l_new_col(4) := 'Never gonna make you cry';
l_new_col(5) := 'Never gonna say goodbye';
l_new_col(6) := 'Never gonna tell a lie and hurt you';
DBMS_TF.put_col(1, l_new_col);
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.
view
CREATE OR REPLACE VIEW dual AS
SELECT *
FROM poly_func(SYS.DUAL)
View created.
select
SELECT *
FROM dual
RICKROLL | Never gonna give you up | Never gonna let you down | Never gonna run around and desert you | Never gonna make you cry | Never gonna say goodbye | Never gonna tell a lie and hurt you |
---|