Oracle PLSQL Demo - 18.02.管道function[查询零散的字段组成list管道返回] [字段必须对上]

--PACKAGE
CREATE OR REPLACE PACKAGE test_141215 is
    TYPE type_ref IS record(
        ENAME VARCHAR2(20),
        SAL NUMBER(10));
    TYPE t_type_ref IS TABLE OF type_ref;

    FUNCTION retrieve(v_name varchar2) RETURN t_type_ref
        PIPELINED;
END test_141215;

-- PACKAGE BODY
CREATE OR REPLACE PACKAGE BODY test_141215 IS
    FUNCTION retrieve(v_name varchar2) RETURN t_type_ref
        PIPELINED IS
        cur_type_ref type_ref;

        Type ref_cur_variable IS REF cursor;
        cur_variable ref_cur_variable;
        --rec_emp type_ref%RowType;
        v_sql varchar2(100) := ‘select t.ename, t.sal/*, t.empno*/ from scott.emp t‘;
    BEGIN

        Open cur_variable For v_sql;

        Loop
            fetch cur_variable
                InTo cur_type_ref;
            Exit When cur_variable%NotFound;

            dbms_output.put_line(cur_variable%rowcount || ‘ -> ‘ || cur_type_ref.ename || ‘   ‘ || cur_type_ref.sal);
            PIPE ROW(cur_type_ref);
        End Loop;
        Close cur_variable;

        RETURN;
    END;
END test_141215;

--Test retrieve
select * from table(test_141215.retrieve(‘asd‘));
时间: 2024-12-17 03:07:43

Oracle PLSQL Demo - 18.02.管道function[查询零散的字段组成list管道返回] [字段必须对上]的相关文章

Oracle PLSQL Demo - 18.01管道function[查询零散的字段组成list管道返回]

--PACKAGE CREATE OR REPLACE PACKAGE test_141213 is TYPE type_ref IS record( ENAME VARCHAR2(20), WORK_CITY VARCHAR2(20), SAL NUMBER(10)); TYPE t_type_ref IS TABLE OF type_ref; FUNCTION retrieve(v_name varchar2) RETURN t_type_ref PIPELINED; END test_14

Oracle PLSQL Demo - 24.分隔字符串function

-- refer: -- http://www.cnblogs.com/gnielee/archive/2009/09/09/1563154.html -- http://www.cnblogs.com/yudy/archive/2012/07/18/2597874.html CREATE OR REPLACE TYPE ty_str_split IS TABLE OF VARCHAR2 (4000); CREATE OR REPLACE FUNCTION splitstr(p_string I

Oracle PLSQL Demo - 19.管道function[查询整表组成list管道返回]

create or replace function function_demo RETURN emp PIPELINED as Type ref_cur_emp IS REF CURSOR RETURN emp%RowType; cur_emp ref_cur_emp; rec_emp cur_emp%RowType; begin Open cur_emp For select * from emp t; Loop fetch cur_emp InTo rec_emp; Exit When c

Oracle PLSQL Demo - 16.弱类型REF游标[没有指定查询类型,已指定返回类型]

declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; rec_emp scott.emp%RowType; v_sql varchar2(100) := 'select * from scott.emp t'; begin Open cur_variable For v_sql; Loop fetch cur_variable InTo rec_emp; Exit When cur_variable

Oracle PLSQL Demo - 20.弱类型REF游标[没有指定查询类型,也不指定返回类型]

declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; v_ename varchar2(10); v_deptno number(2); v_sal number(7,2); v_sql varchar2(100) := 'select t.ename, t.deptno, t.sal from scott.emp t'; begin Open cur_variable For v_sql; Loo

Oracle PLSQL Demo - 02.SELECT INTO单行赋值[SELECT INTO variables]

declare v_sal number; begin select t.sal into v_sal from scott.emp t where rownum <= 1; dbms_output.put_line(v_sal); end;

Oracle PLSQL Demo - 15.强类型REF游标[预先指定查询类型与返回类型]

declare Type ref_cur_emp IS REF CURSOR RETURN scott.emp%RowType; cur_emp ref_cur_emp; rec_emp cur_emp%RowType; v_sql varchar2(100) := 'select * from scott.emp t'; begin -- xxx Open cur_emp For v_sql; Open cur_emp For select * from scott.emp t; Loop f

Oracle PLSQL Demo - 17.游标查询个别字段(非整表)

declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; v_empno scott.emp.empno%type; v_ename scott.emp.ename%type; v_sql varchar2(100) := 'select t.empno, t.ename from scott.emp t'; begin Open cur_variable For v_sql; Loop fetch c

Oracle PLSQL Demo - 11.定义包头[Define PACKAGE]

CREATE OR REPLACE PACKAGE temp_package_demo is v_demo NUMBER(3); PROCEDURE p_demo_1(userid NUMBER DEFAULT v_demo, SAL number); FUNCTION f_demo(userid NUMBER) RETURN BOOLEAN; END temp_package_demo;