Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

calling a pipeline function in a procedure

user650888Apr 25 2021 — edited Apr 25 2021

I have a pipeline function that reads data from a table, given the date
CREATE TABLE PTEST
(
X NUMBER,
MYDATE DATE
);

SET DEFINE OFF;
Insert into PTEST
(X, MYDATE)
Values
(100, TO_DATE('4/4/2021', 'MM/DD/YYYY'));
Insert into PTEST
(X, MYDATE)
Values
(100, TO_DATE('4/5/2021', 'MM/DD/YYYY'));
Insert into PTEST
(X, MYDATE)
Values
(100, TO_DATE('4/2/2021', 'MM/DD/YYYY'));
Insert into PTEST
(X, MYDATE)
Values
(200, TO_DATE('4/3/2021', 'MM/DD/YYYY'));
COMMIT;
Below is the pipeline function that reads from above table

CREATE OR REPLACE PACKAGE my_PKG
IS

CURSOR ctest (pdate date)
is
select x, mydate
from ptest where mydate = pdate;

TYPE c_type IS TABLE OF ctest%ROWTYPE;

FUNCTION getdata (
pdate IN DATE DEFAULT NULL

)
RETURN c_type
PIPELINED;
END my_PKG;
/

CREATE OR REPLACE PACKAGE BODY my_PKG
AS
FUNCTION getdata (
pdate IN DATE DEFAULT NULL
)
RETURN c_type
PIPELINED
AS
v_date DATE;
v_c_type c_type;
v_count PLS_INTEGER := 0;
BEGIN
v_date := pdate;
FOR r IN ctest (v_date
)
LOOP
v_c_type := c_type (r);

  PIPE ROW (r);  
  v\_count := v\_count + 1;  
 END LOOP;  
      RETURN;  

EXCEPTION
when others then null;
END getdata;
END my_PKG;

I am trying to write a procedure where , there will be a cursor that has data for 04-APR and 05-APR,, and i want to call the above pipeline query inside the procedure and the result should be data from mytable for 04-APR and 05-APR (whatever dates we use in the curosr)

CREATE OR REPLACE PROCEDURE P_REPORT
IS
CURSOR C1 IS
SELECT * from PTEST WHERE MYDATE IN ('04-APR-2021','05-APR-2021');
BEGIN
FOR R1 IN C1 LOOP
select * from table (my_PKG.getdata(R1.MYDATE));
END LOOP;
END;

I get the error that PLS-00428: an INTO clause is expected in this SELECT statement

How can I call the pipeline query inside a stored proc ? basically I get the data for one date by using below query, i am trying a PLSQL stored proc that when called, gives data for more than one date

SELECT * FROM TABLE (my_PKG.getdata('02-APR-2021'));
I will be using the stored procedure call in a microsoft power bi report direct query (live), will a ref cursor solve my problem or is there any other way ?

Comments
Post Details
Added on Apr 25 2021
7 comments
1,654 views