How to create Pipelined Functions in Oracle?
Pipeline functions are used to return data in tabular format. It returns the data in the nested table type. Pipeline functions are useful to dump data derived from the complex queries.
- Create the types
CREATE TYPE g_emp_row AS OBJECT(empno NUMBER (4),ename VARCHAR2 (10 BYTE),job VARCHAR2 (9 BYTE),mgr NUMBER (4),hiredate DATE,sal NUMBER (7, 2),comm NUMBER (7, 2),deptno NUMBER (2));/
CREATE TYPE g_emp_tab IS TABLE OF g_emp_row;/
- Pipeline function
CREATE OR REPLACE FUNCTION get_employees (pi_deptno IN NUMBER)RETURN g_emp_tabPIPELINEDASCURSOR c_get_emp (p_deptno NUMBER)ISSELECT empno,ename,job,mgr,hiredate,sal,comm,deptnoFROM emp emWHERE deptno = p_deptno;BEGINFOR l_cnt IN c_get_emp (pi_deptno)LOOPPIPE ROW (g_emp_row (l_cnt.empno,l_cnt.ename,l_cnt.job,l_cnt.mgr,l_cnt.hiredate,l_cnt.sal,l_cnt.comm,l_cnt.deptno));END LOOP;RETURN ;END;/
- Query Example
SELECT *FROM TABLE (get_employees (20))ORDER BY empno;
DROP TYPE g_emp_tab;DROP TYPE g_emp_row;DROP FUNCTION get_employees ;
No comments:
Post a Comment
Please do not add any spam links or abusive comments.