管道函数

create table TT
(
  t1 NUMBER not null,
  t2 DATE
)
/
alter table TT add constraint PK_TT primary key (T1)
/
REATE OR REPLACE PACKAGE pkg_test IS
  TYPE table_tt IS TABLE OF tt%ROWTYPE;
  FUNCTION get_tt RETURN table_tt
    PIPELINED;
END pkg_test;
/
CREATE OR REPLACE PACKAGE BODY pkg_test IS
  FUNCTION get_tt RETURN table_tt
    PIPELINED IS
    PRAGMA AUTONOMOUS_TRANSACTION;
    s     VARCHAR(8000);
    v_row tt%ROWTYPE;
    cur   SYS_REFCURSOR;
  BEGIN
    UPDATE tt SET tt.t2 = SYSDATE;
    COMMIT;
    s := 'SELECT * FROM TT';
    OPEN cur FOR s;
    LOOP
      FETCH cur
        INTO v_row;
      EXIT WHEN cur%NOTFOUND;
      PIPE ROW(v_row);
    END LOOP;
    CLOSE cur;
    RETURN;
  END;
END pkg_test;
/
SQL> SELECT * FROM TABLE(pkg_test.get_tt());
        T1 T2
---------- -----------
         1 2013-09-24


又看到管道函数的资料,记录写法,备查

你可能感兴趣的:(管道函数)