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!

Pipelined Function with execute immediate

Ashu OrclMay 9 2013 — edited May 10 2013
Hello Experts,

I have created a Pipe lined function with execute immediate, due to below requirement;
1) Columns in where clause is passed dynamically.
2) I want to know the data stored into above dynamic columns.
3) I want to use it in report, so I don't want to insert it into a table.

I have created a TYPE, then through execute immediate i have got the query and result of that query will be stored in TYPE.
But when calling the function i am getting
ORA-00932: inconsistent datatypes: expected - got -

Below is my function and type, let me know i am going wrong, and is my logic correct.
CREATE OR REPLACE TYPE OBJ_FPD AS OBJECT
                  (LOW_PLAN_NO VARCHAR2 (40),
                   FPD VARCHAR2 (5),
                   SERIAL_NO NUMBER,
                   CEDIA_CODE VARCHAR2 (2),
                   DT DATE);
----                                      
CREATE OR REPLACE TYPE FPD_TBL_TYPE AS TABLE OF OBJ_FPD;
----
CREATE OR REPLACE FUNCTION FUNC_GET_FPD_DATE (P_LOW_PLAN_NO    VARCHAR2,
                                              P_CEDIA_CODE     VARCHAR2,
                                              P_SERIAL_NO      NUMBER)
   RETURN FPD_TBL_TYPE
   PIPELINED
AS
   CURSOR C1
   IS
          SELECT 'FPD' || LEVEL TBL_COL
            FROM DUAL
      CONNECT BY LEVEL <= 31;

   V_STR        VARCHAR2 (5000);

   V_TBL_TYPE   FPD_TBL_TYPE;
BEGIN
   FOR X IN C1
   LOOP
      V_STR :=
            'SELECT A.low_PLAN_NO,
           A.FPD,
           A.SERIAL_NO,
           A.cedia_code,
           TO_DATE (
                 SUBSTR (FPD, 4, 5)
              || ''/''
              || TO_CHAR (C.low_PLAN_PERIOD_FROM, ''MM'')
              || ''/''
              || TO_CHAR (C.low_PLAN_PERIOD_FROM, ''RRRR''),
              ''DD/MM/RRRR'')
              DT FROM ( SELECT low_PLAN_NO, '
         || ''''
         || X.TBL_COL
         || ''''
         || ' FPD, '
         || X.TBL_COL
         || ' SPTS, SERIAL_NO, cedia_code FROM M_low_PLAN_DETAILS WHERE NVL('
         || X.TBL_COL
         || ',0) > 0 AND SERIAL_NO = '
         || P_SERIAL_NO
         || ' AND cedia_code = '
         || ''''
         || P_CEDIA_CODE
         || ''''
         || ' AND low_PLAN_NO = '
         || ''''
         || P_LOW_PLAN_NO
         || ''''
         || ') A,
           M_low_PLAN_DETAILS B,
           M_low_PLAN_MSTR C
     WHERE     A.low_PLAN_NO = B.low_PLAN_NO
           AND A.cedia_code = B.cedia_code
           AND A.SERIAL_NO = B.SERIAL_NO
           AND B.low_PLAN_NO = C.low_PLAN_NO
           AND B.CLIENT_CODE = C.CLIENT_CODE
           AND B.VARIANT_CODE = C.VARIANT_CODE
CONNECT BY LEVEL <= SPTS';

      EXECUTE IMMEDIATE V_STR INTO V_TBL_TYPE;

      FOR I IN 1 .. V_TBL_TYPE.COUNT
      LOOP
         PIPE ROW (OBJ_FPD (V_TBL_TYPE (I).LOW_PLAN_NO,
                            V_TBL_TYPE (I).FPD,
                            V_TBL_TYPE (I).SERIAL_NO,
                            V_TBL_TYPE (I).CEDIA_CODE,
                            V_TBL_TYPE (I).DT));
      END LOOP;
   END LOOP;

   RETURN;
EXCEPTION
   WHEN OTHERS
   THEN
      RAISE_APPLICATION_ERROR (-20000, SQLCODE || ' ' || SQLERRM);
      RAISE;
END;
Waiting for your views.

Regards,
This post has been answered by BluShadow on May 10 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 7 2013
Added on May 9 2013
13 comments
1,787 views