Results 1 to 7 of 7

Thread: Have you worked with Oracle Pipelined functions?

  1. #1

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Have you worked with Oracle Pipelined functions?

    I am facing an issue trying to use variable binding with a pipeline function in Oracle. I am using ODP .NET for connecting to the database.

    If you want to be familiar with PIPELINED functions, you can read this blog.

    I have very similar code with a difference. My function takes in two parameters that I need to pass to get the table. This is working in SQLPLUS without any issues.

    In my C# code, however things change. My function no longer returns a recordset (data reader), if I use the standard method of assigning the parameters.

    The code will work if I concat the variables in a string.

    Here is the example that doesn't work.
    c# Code:
    1. static OracleDataReader fetchData(OracleConnection oc, string strPONumber)
    2.         {
    3.             try
    4.             {
    5.                 OracleCommand od = oc.CreateCommand();
    6.                 od.CommandType = System.Data.CommandType.Text;
    7.                 od.CommandText = "select * from table(pkg_fetchPOInfo.getPORowsTable(:1,:2))";
    8.                 OracleParameter op1 = new OracleParameter();
    9.                 op1.ParameterName = "1";
    10.                 op1.OracleDbType = OracleDbType.Varchar2;
    11.                 op1.Direction = System.Data.ParameterDirection.Input;
    12.                 op1.Size = 7;
    13.                 op1.Value = strPONumber;
    14.                 od.Parameters.Add(op1);
    15.                
    16.                 OracleParameter op2 = new OracleParameter();
    17.                 op2.ParameterName = "2";
    18.                 op2.OracleDbType = OracleDbType.Varchar2;
    19.                 op2.Direction = System.Data.ParameterDirection.Input;
    20.                 op2.Size = 3;
    21.                 op2.Value = "US";
    22.                 od.Parameters.Add(op2);
    23.  
    24.                 OracleDataReader or = od.ExecuteReader();
    25.                 return or;
    26.             }
    27.             catch (Exception e)
    28.             {
    29.                 Console.WriteLine("Error " + e.ToString());
    30.                 return null;
    31.             }
    32.         }

    Here is the example that does.
    c# Code:
    1. static OracleDataReader fetchData(OracleConnection oc, string strPONumber)
    2.         {
    3.             try
    4.             {
    5.                 OracleCommand od = oc.CreateCommand();
    6.                 string formSQL = "Select * from table(pkg_fetchPOInfo.getPORowsTable('"+strPONumber+"','US'))";
    7.                 od.CommandType = System.Data.CommandType.Text;
    8.                 od.CommandText = formSQL;
    9.                 OracleDataReader or = od.ExecuteReader();
    10.                 return or;
    11.             }
    12.             catch (Exception e)
    13.             {
    14.                 Console.WriteLine("Error " + e.ToString());
    15.                 return null;
    16.             }
    17.         }
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Have you worked with Oracle Pipelined functions?

    No error message written to console?

  3. #3

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Have you worked with Oracle Pipelined functions?

    Quote Originally Posted by leinad31 View Post
    No error message written to console?
    Yes, there is an error code being returned.

    The error being returned is ORA-22905: cannot access rows from a non-nested table item.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Have you worked with Oracle Pipelined functions?

    Might as well post code of pipeline function

  5. #5

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Have you worked with Oracle Pipelined functions?

    The function is part of a package. The function looks something like this.
    sql Code:
    1. create or replace package pkg_fetchPOInfo is
    2. TYPE PO_HEADER_ROW IS RECORD
    3. (      PO_ID INT, --Reference field
    4.        PO_NUMBER VARCHAR2(22), --Reference field
    5.        BRANCH_ID VARCHAR2(3), -- Contains the Operating Unit Id.
    6.        PARTY_NAME VARCHAR2(200), --Could contain VENDOR or MANUFACTURER
    7.        DATE_ORDERED DATE,
    8.        UNIT_NUMBER VARCHAR2(6), --reference to unit number.
    9.        UNIT_HEIGHT NUMBER(15),
    10.        UNIT_WIDTH NUMBER(15),
    11.        UNIT_LENGTH NUMBER(15),
    12.        AMOUNT NUMBER(22,2)
    13. );
    14. TYPE PO_ROWS_TAB IS TABLE OF PO_HEADER_ROW;
    15. function getPORowsTable(iPO_NUMBER IN VARCHAR2, iCountryCode IN VARCHAR2) return PO_ROWS_TAB pipelined;
    16. end pkg_fetchPOInfo;
    17. /
    18. CREATE OR REPLACE PACKAGE BODY pkg_fetchPOInfo
    19. IS
    20. function getPORowsTable(iPO_NUMBER IN VARCHAR2, iCountryCode IN VARCHAR2) return PO_ROWS_TAB
    21.   pipelined
    22.   is
    23.   v_row PO_HEADER_ROW;
    24.   cursor curGetPOInfo is
    25.   SELECT * FROM  get_POMANU_VW_US WHERE po_number = iPO_NUMBER;
    26. begin  
    27. if iCountryCode = 'US' then  
    28. begin
    29.   for x_rec in curGetPOInfo
    30.   loop
    31.       v_row.PO_ID := x_rec.po_id;
    32.       v_row.PO_NUMBER := x_rec.po_number;
    33.       v_row.PARTY_NAME := x_rec.MFG_NAME;  
    34.       v_row.DATE_ORDERED := x_rec.ordered_date;
    35.       v_row.BRANCH_ID := x_rec.gl_branch; --Fin Org Unit code.
    36.       v_row.UNIT_NUMBER := x_rec.unit_number;
    37.       v_row.UNIT_HEIGHT := x_rec.unit_length;
    38.       v_row.UNIT_LENGTH := x_rec.unit_length;
    39.       v_row.UNIT_WIDTH := x_rec.unit_WIDTH;
    40.       v_row.AMOUNT := x_rec.po_amount;
    41.     pipe row ( v_row );
    42.   end loop;
    43.   return;
    44. end;
    45. else
    46. begin
    47.        --Stub for other countries.
    48.        null;
    49. end;
    50. end if;
    51. end getPORowsTable;
    52. end; /*Always mark the package end*/
    53. /
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Have you worked with Oracle Pipelined functions?

    What's strange is that it works in some scenarios, it shouldn't work at all... you didn't use sys_refcursor, nor database scope types (you declared within package, type not in all_types view).

    It may be client-side SQL parsing related since it runs in sqlplus... check version of libraries you are using to connect to oracle database. Make sure it is the latest version.

  7. #7

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Have you worked with Oracle Pipelined functions?

    A variation works for me. The variation is to wrap the function in a stored proc that returns a REFCURSOR. The I use the SYSREFCURSOR datatype to fetch the output.

    I suppose, the only option for me is to use wrap this function with a stored procedure.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width