Skip to main content

Pipelined Functions in Oracle

How to create Pipelined Functions in Oracle? 

Oracle Pipeline function

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_tab
   PIPELINED
AS

   CURSOR c_get_emp (p_deptno NUMBER)
   IS
      SELECT empno,
                        ename,
                        job,
                        mgr,
                        hiredate,
                        sal,
                        comm,
                        deptno
        FROM emp em
       WHERE deptno = p_deptno;
BEGIN
   FOR l_cnt IN c_get_emp (pi_deptno)
   LOOP
      PIPE 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;
Oracle Pipeline function

DROP TYPE g_emp_tab;
DROP TYPE g_emp_row;
DROP FUNCTION get_employees ;

Comments

Popular posts from this blog

Refresh Static region DATA in Oracle APEX

How to refresh Static region data in ORACLE APEX? I have been receiving couple of queries about the static region refresh. In this article, I'll try to get through it. Background: In the Interactive and classic reports data refresh from database is done by AJAX. APEX internally calls the AJAX callback to fetch the data and refresh the report. Reports are followed by their templates, meaning the data is being fetched and merged/replaced with the report templates. Partial refresh during the report search or applying filters also uses the AJAX callback to update and refresh data. Let's try out We need one AJAX callback, One layout, one refresh event and Static Region. Create an AJAX callback Process. There are two places to create it Shared component: Application process - Point AJAX Callback Page Process: Point- AJAX Callback Page Process Application Process Process Name : GET_EMP_DATA Processing Point : AJAX Callback Process code : BEGIN   APEX_JSON.initialize_clob_output;   AP...

Remove Special Character and Extra Space From a String ORACLE/PLSQL

Remove Special Character and Extra Space From a String ORACLE/PLSQL Removing special character using REGEXP: SELECT REGEXP_REPLACE('Sahay*)(^#@Pandey$ashish/Vikas','[^a-z_A-Z ]') FROM DUAL; Remove extra spaces between string using REGEXP: SELECT REGEXP_REPLACE ('Vikas                      Pandey from              Delhi', '[[:blank:]]+', ' ') FROM DUAL; Related Post:  How to Remove New line from a String Using PL/SQL/ORACLE