Passing a .NET collection to a Oracle Stored procedure?

Last post 05-31-2009 9:10 PM by StevenSw. 15 replies.

Sort Posts:

  • Passing a .NET collection to a Oracle Stored procedure?

    04-16-2008, 12:14 PM
    • Member
      97 point Member
    • ibra73
    • Member since 11-26-2007, 9:43 PM
    • Posts 76

    In my ASP.NET page I have a list box.  For each row in the list box, I need to invoke an Oracle SP that inserts some data. How would I go about passing the contents of the list box collection to the Stored procedure so that I can loop through it?

     

  • Re: Passing a .NET collection to a Oracle Stored procedure?

    04-16-2008, 6:11 PM
    • Participant
      1,440 point Participant
    • greg.darling
    • Member since 02-07-2003, 11:50 AM
    • Posts 306

    Hi,

      If you're using Oracle's ODP.net provider, it allows you to pass PLSQL Associative Arrays, which would be the equivalent of passing an array of strings. 

      I don't believe Microsoft's ODP has that functionality though so if you're using it you'd probably need to concatenate the values into comma delimited string for example and then breaking it back up inside the stored procedure.

    Hope it helps, corrections/comments welcome.
    Greg

  • Re: Passing a .NET collection to a Oracle Stored procedure?

    04-20-2008, 11:57 AM

     yes u can pass items in form of array.  dsnt matter what provider u are using. its just the implementation of SP. use looping in SP to insert data.

    Hope it helps. 

     

    Hope it helps.

    -Manas

    =======================================
    If this post is useful to you, please mark it as answer.
  • Re: Passing a .NET collection to a Oracle Stored procedure?

    04-20-2008, 12:59 PM
    • Participant
      1,440 point Participant
    • greg.darling
    • Member since 02-07-2003, 11:50 AM
    • Posts 306

    Hi Manas,

      Do you happen to have a code snippet of that, using System.Data.OracleClient?  I was under the impression that passing PLSQL associative arrays was Oracle ODP.net specific functionality.  I briefly tried, and wasnt able to get it to work using OracleClient. 

      Here's an example using Oracle's ODP:

    http://www.oracle.com/technology/sample_code/tech/windows/odpnet/howto/arraybind/index.html

    Cheers
    Greg

      

  • Re: Passing a .NET collection to a Oracle Stored procedure?

    04-20-2008, 3:18 PM

    you just bind some variables and fetch each row into those variables and then push them into an array.

    Accept the array as a 'PL/SQL table' in the called procedure.

    create type v_array2 as varray(2) of varchar(25);
    create or replace procedure test(name_in in v_array2)
    as
    begin
    for i in 1..2
    loop
    insert into worker
    (name,age,lodging)
    values
    (name_in(i),null,null);
    end loop;
    commit;
    end;

    /

    Hope it helps.

    -Manas

    =======================================
    If this post is useful to you, please mark it as answer.
  • Re: Passing a .NET collection to a Oracle Stored procedure?

    04-21-2008, 11:21 AM
    • Participant
      1,440 point Participant
    • greg.darling
    • Member since 02-07-2003, 11:50 AM
    • Posts 306

    Hi,

      Actually, its the .NET snippet I was looking for, that shows System.Data.OracleClient calling the above procedure you've provided, as an example. 

      With respect to Oracle's ODP, the ability to call a proc with a PLSQL Associative Array has been around for a while.  Calling the above procedure though which takes a UDT (user defined type) requires the very latest version.

      I pasted the wrong link above with respect to passing an array into a procedure, here's the one I meant to post.
         http://www.oracle.com/technology/oramag/oracle/07-jan/o17odp.html

    Cheers,
    Greg

  • Re: Passing a .NET collection to a Oracle Stored procedure?

    04-24-2008, 2:34 PM
    • Member
      97 point Member
    • ibra73
    • Member since 11-26-2007, 9:43 PM
    • Posts 76
    Actually, its the .NET snippet I was looking for, that shows System.Data.OracleClient calling the above procedure you've provided, as an example.  If anyone had the .NET code example that would be great.
  • Re: Passing a .NET collection to a Oracle Stored procedure?

    04-25-2008, 1:54 AM

     See my post here..

    http://forums.asp.net/t/1247854.aspx

     hope it helps.
     

    Hope it helps.

    -Manas

    =======================================
    If this post is useful to you, please mark it as answer.
  • Re: Passing a .NET collection to a Oracle Stored procedure?

    04-25-2008, 10:46 AM
    • Member
      97 point Member
    • ibra73
    • Member since 11-26-2007, 9:43 PM
    • Posts 76

    No im not talking about a ref cursor parameter.  I am talking about an associative array parameter.  Is there a way to pass it through .net code?

  • Re: Passing a .NET collection to a Oracle Stored procedure?

    05-27-2008, 3:56 PM
    • Member
      4 point Member
    • johnsimon66
    • Member since 05-27-2008, 7:48 PM
    • Posts 2

    I am having the same problem - tried to pass input parameter to oracle stored procedure thru System.Data.OracleClient.

    Tried using associative array and varray as a parameter type but it doesn't work.

    I thing that Manas is not understanding what the problem is.

    It is NOT how to declare associative array as a parameter in a stored procedure. 

    It is NOT how to get a cursor back as an output parameter.

    It IS how to pass an array from .Net as an INPUT parameter by using System.Data.OracleClient.

    Does somebody knows where can I get the oracle data provider?

  • Re: Passing a .NET collection to a Oracle Stored procedure?

    05-07-2009, 8:11 PM
    • Member
      4 point Member
    • vrakesh
    • Member since 04-21-2009, 8:48 PM
    • Posts 4

    Can anybody provide solution for this. I have been working on the same issue with no luck.

    thanks!

  • Re: Passing a .NET collection to a Oracle Stored procedure?

    05-09-2009, 8:02 AM
    • Member
      4 point Member
    • johnsimon66
    • Member since 05-27-2008, 7:48 PM
    • Posts 2

     Hi,

    I am currently using a workarround: I send the input parameter as a delimited string and on the oracle side I use a split function to convert the delimited string into oracle collection (usually associative array).  You can use different delimiters and achieve multiple level of splitting, which will bring you closer to mimicing an object. I know that this is not a perfect solution and also tedious but unless Oracle extends it's object oriented features to include input parameters in the picture this will still work. You can use the same idea as an output parameter as well - mimic an object thru delimiters on Oracle side and split it on the .Net side provided that cursor output doesn't work for you.

     John

  • Re: Passing a .NET collection to a Oracle Stored procedure?

    05-19-2009, 4:58 PM
    • Member
      16 point Member
    • row118
    • Member since 07-02-2007, 7:05 AM
    • Posts 34
    John this is exactly what I'm trying to accomplish.  The following is pseudocode for my Oracle Stored Proc. 
     
    CREATE PROCEDURE SelectFromList 
    (
    delimitedList varchar2(100);   -- 
    --- or 
    type TableValues of number; 
    AS
    BEGIN
        Select * From MyTable Where StoreId in (5,6,7,8) ;
          OR 
       Select * From MyTable where StoreId in (select Storeid from the table input)
    END ; 
    
     --------------------------------------
    With passing in the table,  what type of variable and how is it populated from cmd parameters in web page (or app) .
     For instance, can you pass an Oracle Array and will be CAST into table by the Oracle Stored Procedure? 
    I have parsing code for delimited list. In the case of the string, I want to define a table and on each loop, Insert into the table. 
    
     
  • Re: Passing a .NET collection to a Oracle Stored procedure?

    05-19-2009, 5:52 PM
    • Member
      16 point Member
    • row118
    • Member since 07-02-2007, 7:05 AM
    • Posts 34

    Ho do i put this is  a code window? Sorry about the formatting.  

    I get the same errors when I execute this statement:

    CReate type mytype as table of varchar2(100);

       select * from table (mytype('1','2','a'))
     /

    ERROR:

    CReate type mytype as table of varchar2(100);
    *
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [17182], [0x59E057D4], [], [], [], [], [], []

  • Re: Passing a .NET collection to a Oracle Stored procedure?

    05-19-2009, 7:02 PM
    • Member
      16 point Member
    • row118
    • Member since 07-02-2007, 7:05 AM
    • Posts 34

    I followed this link suggested:And got the same errors as above. When I executed on 10g, I had no problems. everything worked like a charm. I had been using the 9i client.

Page 1 of 2 (16 items) 1 2 Next >