Create the PTF implementation package split_p.
CREATE PACKAGE split_p AS
FUNCTION describe(tab IN OUT DBMS_TF.table_t,
col DBMS_TF.columns_t,
cnt NATURALN)
RETURN DBMS_TF.describe_t;
PROCEDURE fetch_rows(cnt NATURALN);
END split_p;
Package created.
Create the PTF implementation package body split_p.
CREATE PACKAGE BODY split_p AS
FUNCTION describe(tab IN OUT DBMS_TF.Table_t,
col DBMS_TF.Columns_t,
cnt NATURALN)
RETURN DBMS_TF.describe_t
AS
new_cols DBMS_TF.columns_new_t;
col_id PLS_INTEGER := 1;
BEGIN
FOR i IN 1 .. tab.column.count LOOP
FOR j IN 1 .. col.count LOOP
IF (tab.column(i).description.name = col(j) AND
tab.column(i).description.TYPE = DBMS_TF.type_number) THEN
tab.column(i).pass_through := FALSE;
tab.column(i).for_read := TRUE;
new_cols(col_id) := tab.column(i).description;
col_id := col_id + 1;
END IF;
END LOOP;
END LOOP;
RETURN DBMS_TF.describe_t(new_columns=>new_cols, row_replication=>true);
END;
PROCEDURE fetch_rows(cnt NATURALN)
AS
inp_rs DBMS_TF.row_set_t;
out_rs DBMS_TF.row_set_t;
rows PLS_INTEGER;
BEGIN
DBMS_TF.get_row_set(inp_rs, rows);
FOR c IN 1 .. inp_rs.count() LOOP
FOR r IN 1 .. rows LOOP
FOR i IN 1 .. cnt LOOP
out_rs(c).tab_number((r-1)*cnt+i) := inp_rs(c).tab_number(r)/cnt;
END LOOP;
END LOOP;
END LOOP;
DBMS_TF.put_row_set(out_rs, replication_factor => cnt);
END;
END split_p;
Package Body created.
Create the standalone PTF named split.
CREATE FUNCTION split(tab TABLE,
col columns,
cnt NATURALN)
RETURN TABLE
PIPELINED ROW POLYMORPHIC USING split_p;
Function created.
Invoke the split PTF in a query.
SELECT ename, sal, comm
FROM split(scott.emp, COLUMNS(sal, comm), cnt => 2)
WHERE deptno=30
ENAME | SAL | COMM | BLAKE | 1425 | - | BLAKE | 1425 | - | ALLEN | 800 | 150 | ALLEN | 800 | 150 | WARD | 625 | 250 | WARD | 625 | 250 | MARTIN | 625 | 700 | MARTIN | 625 | 700 | TURNER | 750 | 0 | TURNER | 750 | 0 | JAMES | 475 | - | JAMES | 475 | - |
---|